Git basic tutorial
The following is actually a basic tutorial for Git use within the company. I will record it here.
Modify Git configurations
Windows operating system line feed Configuration
git config --global core.autocrlf input
User name and email Configuration
git config user.name yourname --local
git config user.email yourname@tudou.com --local
Clone v3 code library
git clone git@gitlab.intra.tudou.com:static/v3.git
View Branch
List all local branches
git branch
List all remote branches
git branch -r
Create Branch
Create based on local branch
git branch [BRANCH_NAME]
git push origin [BRANCH_NAME]
Create a remote Branch
git branch [BRANCH_NAME] origin/master
Bind a local branch to a remote Branch
After binding, the operation can be omitted.
Origin [branch], which is more convenient and efficient to use. Of course, if multiple remote operations are required, it cannot be omitted.
git push -u origin [branch]
Switch Branch
Switch to the local branch. If the local branch does not exist, the system automatically searches for the remote branch.
git checkout [BRANCH_NAME]
Update Branch
Update master
git pull --rebase origin master
Resolves rebase conflicts.
git status
# Open the corresponding file as prompted, search for the "<" character, and execute
git add -u
git rebase --continue
# Stop the pull Operation and return to the status before pull rebase.
git rebase --abort
Code submission
Submit to local version Library
git commit -m "commit message"
Submit to remote master
git push origin master
Merge Branch
Switch to the master.
git checkout master
Merge branches.
git merge --no-ff [BRANCH_NAME]
Resolves conflicts in the src directory.
https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line
Use external tools to resolve conflicts
Resolves all conflicts in this merge.
git mergetool
Resolve conflicts with specific files
Git mergetool src/js/g. js
Re-build all conflicting files under the build and dist directories.
ytpm [PATH]
Submit the code.
git add .
git commit -m "commit message"
Restore code
Discard local modification (discard all local uncommitted files, consistent with remote)
git reset --hard origin/master
Restore A submission
git revert [COMMIT_ID]
Restore merge
git revert -m 1[MERGE_COMMIT_ID]
Restore to the specified version
git reset --hard [COMMIT_ID]
Delete Branch
Delete local branch
git branch -d [BRANCH_NAME]
Delete remote Branch
git push origin --delete[BRANCH_NAME]
View change records
View change history
git log --decorate --numstat [PATH]
View A submission record
git show --name-only [COMMIT_ID]
Comparison File
Git default mode
Compare the workspace version with the temporary workspace version.
git diff --[PATH]
Compare the version of the temporary storage area and version Library
git diff --cached --[PATH]
Compare the workspace version and version library version (HEAD)
git diff HEAD --[PATH]
Compare two submitted files
git diff [COMMIT_ID_1][COMMIT_ID_2]--[PATH]
Compare two branch files
git diff develop master -- src/js/g.js
git diff develop:src/js/g.js master:src/js/g.js
View files on other branches
git show master:src/js/g.js
Comparison with external comparison tools
Compare all the modifications in this merge (only compared with the records before submission)
git difftool
Compares the historical versions of a specified file.
git difftool [GitHash] HEAD -- src/js/g.js
Solution when developing on develop accidentally
Not submitted
git stash
git checkout [BRANCH_NAME]
git stash pop
Submitted
Git log-1 # Remember the COMMIT ID
git reset --hard origin/develop
git checkout [BRANCH_NAME]
git cherry-pick [COMMIT_ID]
Solution when you accidentally merge the branches created by develop or based on develop into the master
A--M---B <---develop
\
--C--G---J---P---Q <---master
In the preceding example, you need to confirm the error submission point of J and the hash value of the previous and later submission points, and ensure that the current HEAD is on Q, and then execute:
git rebase -i -p --onto P G
After execution, you need to manually resolve the conflict after each submission. After manual comparison, You can execute the following commands:
Git add. // add this conflict Modification
git rebase --continue
Note that the above steps may be performed many times, and each time the above method is used. For manual comparison methods, see [external comparison tool] [1.
Others
Beyond Compare comparison tool Configuration
In ~ /. Add the following configuration to the gitconfig file. The comparison tool is Beyond Compare. You can download it by yourself. If you are a win user, you need to modify the corresponding path.
In addition, Beyond Compare 4 for Mac also needs to be set to support calling through command Line: Click the menu-> Install Commond Line Tools... and then enter the system logon password.
[Merge]
Tool = bcomp
[Mergetool]
Prompt = false
KeepBackup = false
[Mergetool "bcomp"]
TrustExitCode = true
Cmd = "/usr/local/bin/bcomp" "$ LOCAL" "$ REMOTE" "$ BASE" "$ MERGED"
[Diff]
Tool = bcomp
[Difftool]
Prompt = false
[Difftool "bcomp"]
TrustExitCode = true
Cmd = "/usr/local/bin/bcomp" "$ LOCAL" "$ REMOTE"
Common git Alias
[alias]
st = status --short--branch
pu = pull --rebase
ca = commit --amend
ci = commit -a -v
br = branch
bv = branch -vv
co = checkout
cb = checkout -b
df = diff
un = reset --hard HEAD
uh = reset --hard HEAD^
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]"--decorate --numstat
ld = log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]"--decorate --date=short--graph
ls = log --pretty=format:"%C(green)%h\\ %C(yellow)[%ad]%Cred%d\\ %Creset%s%Cblue\\ [%cn]"--decorate --date=relative
GitHub Tutorials:
GitHub tutorials
Git tag management details
Git branch management
Git remote repository details
Git local Repository (Repository) Details
Git server setup and Client installation
Git Overview
Share practical GitHub tutorials
How to Build and use Git servers in Ubuntu
Git details: click here
Git: click here
This article permanently updates the link address: