Configuration
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe @example.com
Creating a repository
$ git clone [url] #cloning a remote repository
$ git clone git://github .com/schacon/grit.git
$ git clone git://github.com/schacon/grit.git mygrit
$ git clone --bare my_project my_project.git #Create pure Warehouse
$ git init #Initialize local repository
$ git init --bare #Create a pure repository
Modify and submit
< $ git status #View Status
$ git diff #View Changes
$ git diff --cached #View between the file that has been temporarily saved and the snapshot that was last submitted Differences
$ git diff master...contrib #properties branch co The difference between ntrib and its common ancestor with the master branch (new code that will actually be introduced when merging)
$ git add . #Track all changed files
$ git add [ ,null,null,3],File] #Track the specified file
$ git mv [old] [new] #文件 rename
$ git rm [file] # 删除文件
$ git rm - -cached [file] # Stop tracking files but not delete
$ git commit -m "commit message" #Submit all updated files
$ git commit --amend #修改最后Submit once
$ git commit -a -m 'added new benchmarks' # Skip staging area direct commit
View commit history
$ Git log #View commit history
$ git log --pretty=oneline
$ git log -p [file] #View the commit history of the specified file
$ git log Master..experiem Nt #All commits that can be obtained from the experiment branch but not from the master branch
$ git blame [file] #View the commit history of the specified file in a list
$ git log origin /featureA ^featureA #Compare the origin/featureA and featureA branches to see what the original/featureA has updated
Undo
$ git reset --hard HEAD #Undo work Modifications for all uncommitted files in the directory
$ git reset --hard [commit] # will fall back to a [commit]
$ git reset HEAD [file] # Cancel Saved file
$ git checkout HEAD [file] #Undo the modified content of the specified uncommitted file [scratched]
$ git checkout -- benchmarks.rb #Cancel the file Modify [Unstaged]
$ git revert [commit] #Undo the specified commit
Branches and tags
$ git branch #Show all Local branch
$ git checkout [branch/tag] #Switch to the specified branch or tag
$ git checkout -b featureB origin/master #Clone from branch origin/master and create branch featureB, switch to featureB
$ git branch [new-branch] #Create a new branch
$ git branch sc/ruby_client master #Clone a sc/ruby_client branch from the master branch
$ git Branch -d [branch] #delete local branch
$ git branch --merged #See which branches have been merged into the current branch
$ git branch --no-merged #View which branches Not merged into current branch
$ git tag #List all local tags
$ git tag [tagname] #Create tags based on latest commits
$ git tag -d [tagname] # 删除标签
Merge and Rebase
$ git merge [branch] #Merge the specified branch to the current branch
$ git rebase [branch] #Rebase the specified branch to the current branch
Remote operation
$ git remote -v #View remote repository information
$ git remote show [remote] #View specified remote repository information
$ git remote add [remote] [url] #add remote repository
$ git remote rename [ ,null,null,3],Old-remote-name] [new-remote-name] #Rename of remote repository
$ git remote rm [remote] #remote repository deletion
$ git fetch [remote] # Get code from remote library
$ git pull [remote] [branch] #Download code and merge quickly to current branch
$ git push [remote] [branch] #upload code and quick merge
$ git push origin featureB[local branch]:featureBee[remote branch] #push local branch to the specified remote branch
$ git push [remote] :[branch/tag-name] #去除远Branch or tag
$ git push --tags #upload all tags
other
$ git describe master #generate build number
$ git archive master --prefix='project/' |
Gzip > 'git describe master'.tar.gz #packaged into tar
$ git archive master --prefix='project/' --format=zip > 'git describe master'.zip #package Into zip
$ git stash #存储
$ git stash list #View the list of storage
$ git stash apply stash@2 #Apply the storage named stash@2. If you don't specify it, Git uses the most recent repository by default and tries to apply it
$ git stash drop stash@{0} #Remove the repository named stash@{0}
$ git Blame -L 12,22 simplegit.rb #文件`
Git file
.gitattributes #property file
.doc diff= worddatabase.xml merge = ours
.gitignore # ignore certain files
# this is a comment & ndash; Git will be ignored * [oa] #. Ignore all files ending in .o or .a! lib.a # except lib.a except /TODO # Ignore TODO files in the root directory of the project, excluding subdir/TODObuild/# Ignore all files in the build/directory doc/*.txt # will ignore doc/notes.txt but not doc/server/arch.txt