This article is a beginner reprint:http://justcoding.iteye.com/blog/1830388
Another official reading address: Https://git-scm.com/book/zh/v2
Initialize configuration
#Configure the name of the person using the Git repositorygit config--global user.name"Your Name Comes here"#Configure people to use the Git repository emailgit config--global user.email [email protected]yourdomain.example.com#Configure to cache default 15 minutesgit config--Global Credential.helper Cache#Modify Cache Timegit config--global credential.helper ' cache--timeout=3600' git config--global Color.uitruegit config--global alias.co checkoutgit config--global Alias.ci commitgit config--global Alias.st statusgit config--global alias.br branchgit config--global Core.editor"mate-w" #set Editor to use TextMateGit config-1#List all Configurations#user's git configuration file ~/.gitconfig
view, add, submit, delete, retrieve, reset modified files
git help <command>#Show Command's HelpGit show#Show content for a commitGit show$idgit Co--<file>#Discard work Area modificationsGit Co.#Discard work Area modificationsgit add <file>#Submit work file modifications to local staging areagit Add.#submit all the modified work files to staging areagit rm <file>#Delete files from the repositorygit rm <file>--cached#delete files from repository without deleting filesgit reset <file>#recovering from staging area to working filesgit reset--.#recovering from staging area to working filesgit reset--hard#restores the state of the most recent commit, that is, discard all changes since the last commitgit ci <file>git ci. Git ci-A#combine git add, git rm and git ci to do all of these things togetherGit ci-am"some comments"git ci--amend#modify the last commit recordgit revert <$id>#restores the state of a commit, and the recovery action itself creates a commit objectgit revert HEAD#Restore the status of the last commit
View File diff
git diff <file> # Compare current file and staging area file differences git diffgit diff <$id 1> <$ Id2> # Compare differences between two commits # compare git diff--staged between two branches # Compare staging area and repository diff git diff--cached # Compare staging Area and Repository diff git diff--stat # Compare statistics only
View Commit record
git log git log <file> # view the file for each commit record git log-p <file> # view diff git log-p-2 # for each detail modification See the last two details of the changes in the diffgit log--stat # View submission statistics
Tig
You can use TIG instead of diff and Log on your Mac.brew install tig
Get git repository
# initializing a repository of repositories git init # clone remote repository git clone [email protected]xbc.me:wordpress.git# Add Remote repository origin, syntax for git Remote add [shortname] [url]git remote add origin [email protected]xbc.me:wordpress.git# View the remote repository git remote-v
Submit your changes
#Add the currently modified file to staging areagit Add.#If you automatically track files, including files that you have manually deleted, the status is deletedgit add-u#Submit your changesGit commit–m"your notes."#Push your updates to a remote server with the syntax git push [remote name] [local branch]:[remote branch]git push Origin master#View file Statusgit status#track new Filesgit add readme.txt#Remove files from the current trace list and remove them completelygit rm readme.txt#Delete only in staging area, keep files in current directory, no longer trackgit rm–cached readme.txt#Renaming Filesgit mv reademe.txt Readme#View the history of a submissiongit log#Modify the last commit comment, using the –amend parameterGit Commit--Amend#forgetting to commit some changes, the following three commands will only get one commit. git commit–m "add readme.txt"git Add readme_forgottengit commit–amend#Let's say you've already used git Add., add the modified files A, B to staging area#Now you just want to submit a file, do not want to submit B file, shouldgit reset HEAD b#to cancel the modification of a fileGit checkout–-readme.txt
view, toggle, create, and delete branches
Git br-r#Viewing remote branchesgit br <new_branch>#Create a new branchGit br-v#View the last commit information for each branchgit br--merged#view branches that have been merged into the current branchgit br--no-merged#view branches that have not been merged into the current branchgit co <branch>#Switch to a branchGit Co-b <new_branch>#Create a new branch and switch to the pastgit Co-b <new_branch> <branch>#Create a new new_branch based on branchgit Co$id #Checkout A history commit record, but without branching information, switching to another branch will automatically deleteGit Co$idb <new_branch>#Checkout A History submission record and create a branchgit br-D <branch>#Delete a branchGit br-d <branch>#Force a branch to be removed (a branch that has not been merged will need to be forced when it is deleted)
Branch Merging and Rebase
git merge <branch> # Merge branch branches into the current branch git merge origin/master--no-ff # Do not fast-foward merge so you can generate merge commit git rebase master <branch> # will master Rebase to Branch, equivalent to:git co <branch> && git rebase master && git co master && git merge &l T;branch>
git patch management (for easy development of synchronization on multiple machines)
git diff >: /sync.patch # build patch git apply: /sync.patch # play patch git apply--check. /sync.patch # Test Patch Success
git staging management
git stash # staged git stash list # column all stashgit stash apply # Recovering staged content git stash drop # Delete Staging Area
git remote branch management
Git pull#crawl all branches of remote repository update and merge to localGit pull--no-ff#Crawl All branch updates of the remote repository and merge them locally, not fast-forward mergeGit fetch origin#crawling remote repository updatesgit merge Origin/master#Merge the remote Master branch to the local current branchGit Co--track origin/branch#track a remote branch to create the appropriate local branchgit Co-b <local_branch> origin/<remote_branch>#Create local branch based on remote branch, same as abovegit push#Push All branchesGit push Origin Master#Push the local landlord branch to the remote main branchGit push-u Origin Master#Push the local landlord branch to the remote (if no remote main branch is created to initialize the remote repository)Git push Origin <local_branch>#Create remote Branch, origin is remote warehouse nameGit push Origin <local_branch>:<remote_branch>#To create a remote branchGit push Origin:<remote_branch>#Delete the local branch (git br-d <branch>) before you push to delete the remote branch
Basic Branch Management
#Create a branchgit branch iss53#switch working directory to iss53git chekcout iss53#combine the above commands together to create a ISS53 branch and switch to ISS53git chekcout–b iss53#Merge iss53 branches, current working directory is mastergit merge iss53#after the merge is complete, there is no conflict, delete the ISS53 branchgit branch–d iss53#pull data from remote repository, syntax for git fetch [remote-name]git fetch#fetch pulls up the latest remote repository data, but does not automatically merge to the current directorygit Pull#to view information about a remote warehousegit remote show Origin#establish a local dev branch to track the develop branch of the remote repositorygit checkout–b Dev origin/develop
git remote repository management
git remote-v # View remote server address and warehouse name git remote show Origin # View Remote server warehouse status git Remote add origin [email protected] github:robbin/robbin_site.git # Add repository address # Set the remote warehouse address (used to modify the remote warehouse address)git remote rm <repository> # Delete a repository
Create a remote warehouse
git clone--bare robbin_site robbin_site.git#Create a version-only warehouse with a versioned projectScp-r my_project.git [email protected] git.csdn.net:~#upload the repository to the servermkdir robbin_site.git&& cd robbin_site.git && git--bare init#Create a pure warehouse on the servergit remote add origin [email protected] Github.com:robbin/robbin_site.git#set the remote warehouse addressGit push-u Origin Master#Client First CommitGit push-u origin Develop#The local develop branch is submitted to the remote develop branch for the first time, and the trackgit remote set-head Origin Master#set head of remote warehouse to point to master branch
You can also command settings to track remote libraries and local libraries
Git branch--set-upstream master origin/--set-upstream Develop Origin/develop
git-Common Commands