Git tips-instruction aliases and using beyond Compare as a diff diff tool

Source: Internet
Author: User
Tags diff file diff

Objective

This article is written primarily for users who use the command line to manipulate git to improve the efficiency of git usage. As for the use of commands or GUI (tortoise git or vs git plugin) is not discussed here, people choose according to their own preferences. I personally prefer to use the command line, because the command line is the native client, when familiar with the command line, the use of efficiency is not lower than the GUI. And I was from the GUI (Tortoise SVN) to the command line, just at the beginning of the spat command line "non-human", but I walked out of the comfort zone, the actual use of the command line, I found that my previous thoughts are superficial.

Instruction aliases

An instruction alias is a short instruction alias for some commonly used instructions to improve the efficiency of git.

Like Git st (git status):

  

  

Using an instruction alias does not overwrite the original instruction, but it also takes effect at the same time:

  

When the command alias is wrong, there will be a hint:

  

I am here to share my set of command aliases, hoping to help improve usage efficiency.

1. View status (show the working tree status)-Git status

Git St

  

2. Commit (Record changes to the repository)-git commit

Git ci

  

3. Branching operations (List, create, or delete branches)-Git branch

Git BR

4. Check out (Switch branches or restore working tree files)-Git checkout

Git Co

To check out a branch:

  

Check out (Restore) workspace files:

  

Check out (restore) All files in the workspace:

  

5. diff (Show changes between commits, commit and working tree, etc)-git diff

Differences between the workspace (working driectory) and staging area (staging area):

Git DF

Individual file differences:

  

All file differences:

  

Staging Area (staging area) differs from the local warehouse (repository):

Git Dfs

Individual file differences:

  

Multiple file differences:

  

6. Merge (Join double or more development histories together)-git merge

Git Mr

  

7. Log (Show commit logs)-git log

To view a recent log:

Git last

  

  

To view log and branch submission information:

Git ls

  

Where the green represents the local branch, the red Representation of the host branch, as can be seen from the local master branch, host's Master branch, the host's dev branch are all in the same commit, the local dev branch is ahead of the 3 branches mentioned earlier. When the version display is not fully committed, you can press ENTER (enter) to continue loading the commit, need to exit Yes, press the letter Q. Alternatively, you can specify "-N" to view the top N records:

  

View Log, branch submission information, author, submission time:

GIT LG

When the version display is not fully committed, you can press ENTER (enter) to continue loading the commit, need to exit Yes, press the letter Q. Alternatively, you can specify "-N" to view the top N records:

  

8. Variable base (reapply commits on top of another base tip)-Git rebase

Git RB

  

I understand that the rebase and merge functions are similar, except that after the rebase operation, the submission will basically be on one line, and the merge will fit from one line to another.

Merge:

  

  

Rebase:

  

9. Picking (Apply the changes introduced by some existing commits)-Git Cherry-pick

Git CB

  

See, Cherry-pick is to copy a commit as a new commit, and merge or rebase effect is different, check pick can be done after the merge or rebase operation:

  

Using the Beyond Compare as the diff comparison tool

The command line comes with a file diff tool that is relatively simple to view or compare file differences, which may not work well, especially when resolving conflicts, but we can integrate some of the more powerful diff tools, such as the Beyond Compare mentioned in this article. So, let's take a look at the example:

The difference between the results of their own:

  

Use the Difftool directive to invoke the comparison effect of Beyond compare:

  

  

Of course Difftool can also use command aliases:

  

  

Resolve Merge Conflicts:

We add "dev" content to the dev a.txt file, add "master" to the master branch, and then merge Dev with the Master branch.

  

  

To invoke the Beyond Compare merge conflict using the Mergetool directive:

  

  

As can be seen, the left side is the current version of the branch, the right is the version of the branch that needs to be merged, the middle is the same part of the version, the policy of dealing with the conflict is about the following:

To replace the merged branch version #1 the current branch version, click the green arrow.

#2 Merge Branch version to replace the current branch version, click the pink arrow.

#3 also requires two versions of the content, click the green or pink arrows, and then copy the contents of the other branch to the text edit box below.

#4 as long as the content of the same part, do nothing.

#5 other.

  

Finally, click on the red exclamation point to indicate that the conflict has been resolved. Here I choose the strategy of # #:

  

Close beyond Compare to complete the merge operation.

How to configure

. Gitconfig is the primary file for the configuration, which is typically in the c:\users\{user name} directory and, if not, can be created in two steps:

#1 Open command-line tools

  

  

#2 execute instructions to set the user name or set the mailbox.

Set User name:

git config--global user.name "{Your username}"

  

Set up your mailbox:

git config--global user.email "{Your email}"

  

Open the. gitconfig file, copy the following to the file, and complete the configuration of the instruction alias:

[Alias]
St = Status
CI = Commit
CO = Checkout
BR = Branch
DF = diff
DFT = Difftool
DFS = diff--staged
DFTs = Difftool--staged
Mr = Merge
MRT = Mergetool
last = Log-1 HEAD
ls = log--oneline--graph--all--decorate
LG = Log--oneline--graph--all--decorate--pretty=format: "%h%x20%cgreen%d%x20%cred%an%x20%c (yellow)%ad%x20%Creset% S "--full-history--date=short
RB = Rebase-i
CP = Cherry-pick

Open the. gitconfig file, copy the following to the file, and complete the configuration of the Beyond Compare:

[diff]
Tool = Bc4
[Difftool]
prompt = True
[Difftool "Bc4"]
cmd = \ "D:/program files/beyond Compare 4/bcomp.exe\" "$ (cygpath-w $LOCAL)" "$REMOTE"
[Merge]
Tool = Bc4
[Mergetool]
prompt = True
[Mergetool "Bc4"]
#trustExitCode = True
cmd = \ "D:/program files/beyond Compare 4/bcomp.exe\" "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

Final effect:

  

At last

Hope that the above share of the small skills can improve the efficiency of everyone, you can also according to their own needs to set the command alias, welcome to discuss and share instructions on the use of aliases.

Git tips-instruction aliases and using beyond Compare as a diff diff tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.