Summary of git commands
1) Basic environment 1) Local initialization: Generate. git directory, do not easily modify the command: git init 2) Set signature: distinguish the identity of different developers, the signature set here has nothing to do with the account and password of logging in to the remote library (code center);* Project level/repository level: Valid only in the current local library range Command: git config www.example.com adminit config www.example.com admin@admin.com Location of information saved: . git/config file * System user level: Log in to the user scope of the current operating system Command: git config--global www.example.com adminit config--global www.example.com admin@admin.com Location of information saved:~/. gitconfig * Level Priority: (1) Proximity Principle: Project level takes precedence over system user level. If both of them exist, the signature at project level shall be adopted;(2) if only the signature at system user level exists, the signature at system user level shall prevail;(3) if neither of them exists, errors will be reported frequently in future operations; 2) basic operation git status #View status of workspace and staging area git add 123.txt #Commit workspace files to staging area (either for individual files or using ". "indicates all files in the current directory) git rm--cached 123.txt #Withdraw the file from the staging area and put it back in the workspace git commit-m "first commit 123.txt"#Commit the contents of the staging area to the local repository (-m description information, plus file name and no file name) 3) Several ways to view the history git log #View log messages from previous commits git log--pretty = oneline #View log information from previous commits (displayed as a single line) git log--oneline #View log information of previous commits (displayed in a more concise way) git reflog #HEAD pointer showing all history 4) Control version forward and backward
1) Operation based on index value (recommended)
git reset --hard d67b2ca #--hard is followed by the index value found by git reflog command
2) Use ^symbol (only backward)
git reset --hard HEAD^ #Go back one version (^one means go back one version)
3) Use~symbol (only backward)
git reset --hard HEAD~n #n means step back 5) Delete files and retrieve them
Premise: Before deletion, the existing state of the file was submitted to the local repository;
Operation:
git reset--hard [pointer position]
1) Delete operation has been committed to local library: pointer location points to history record;
2) Delete operation has not been committed to local library: pointer position uses HEAD;
6) Compare file differences git diff [file name] #Compare files in workspace to cache git diff [historical versions in local repository][filename] #Compare files in workspace to local repository history git diff [version history in local repository] #Compare all files in workspace with local libraries 7) git branch management git branch [branch name] #Create branch git branch-v #View all branches,"*" indicates the current branch (-v option is not added) git checkout [branch name] #switch branch git checkout-b [branch name] #Create branches and switch branches git merge [merged branch name] #Quickly merge branches (if not on merged branches) git branch - d [branch name] #Remove specified branch git branch - D [branch name] #Forcefully delete specified branch git stash #Temporarily store the state of the current repository git stash pop #Restore and delete temporarily stored information git stash apply #Restore temporarily stored information without deleting information git stash drop #Delete temporarily stored information git stash show #View temporarily stored information git remote add origin www.example.com #alias the remote repository address with originit remote #Check whether the current repository belongs to a remote repository git remote-v #View details git push origin master #Push local master branch to remote repository git checkout-b dev origin/dev #Create local dev branch and link to dev branch of remote repository git fetch origin master #Download from remote repository to local git merge origin/master #Merge remote branches git pull origin master #Download master branches of remote repositories locally and merge them, mainly to resolve conflicts git branch--set-upstream-to = origin/dev Associate the local dev branch to the dev branch of the remote repository git branch-r-d origin/dev Delete the specified remote dev branch git push origin :dev Commit deleted remote branches to remote repositories