[Reprint] List of commonly used Git commands

http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html

 

Extract several git commands

 

#delete remote branch

$ git push origin --delete [branch-name]

 

#Select a commit to merge into the current branch

$ git cherry-pick [commit]

 

#Establish a tracking relationship between the existing branch and the specified remote branch

$ git branch --set-upstream [branch] [remote-branch]

 

#Use a new commit to replace the previous commit

#If the code does not have any new changes, it is used to rewrite the commit information of the last commit

$ git commit --amend -m [message]

 

#Redo the last commit and include the new changes in the specified file

$ git commit --amend [file1] [file2] ...

 

#Delete the workspace file and put this deletion into the staging area

$ git rm [file1] [file2] ...

 

#Stop tracking the specified file, but the file will remain in the workspace

$ git rm --cached [file]

 

#Rename the file and put this renamed into the temporary storage area

$ git mv [file-original] [file-renamed]

 

 

Git 's setting file is .gitconfig , which can be in the user's home directory (global configuration) or in the project directory (project configuration).

#Display the current Git configuration

$ git config --list

 

#Edit Git configuration file

$ git config -e [--global]

 

#Set the user information when submitting the code

$ git config [--global] user.name "[name]"

$ git config [--global] user.email "[email address]"

 

#Display the version history of a file, including file name changes

$ git log --follow [file]

$ git whatchanged [file]

 

#Display each diff related to the specified file

$ git log -p [file]

 

#Display the difference between the staging area and the working area

$ git diff

 

#Display the difference between the staging area and the last commit

$ git diff --cached [file]

 

#Display the difference between the workspace and the latest commit of the current branch

$ git diff HEAD

 

# show the difference between two commits

$ git diff [first-branch]...[second-branch]

 

#Display files that have changed in a commit

$ git show --name-only [commit]

 

#Display the content of a file when a certain submission is made

$ git show [commit]:[filename]

 

#Restore the specified file of a commit to the workspace

$ git checkout [commit] [file]

 

#Generate a compressed package ready for distribution

 

$ git archive

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326710587&siteId=291194637