1, intelligent program Ape want to lazy. So we are in the home folder to add a global configuration:. Git/config. and define shortcut keys:
[alias] co = checkout CI = commit st = Status PL = Pull PS = Push dt = Difftool L = Log --stat CP = Cherry-pick CA = commit-a B = Branch
2, now. Start by explaining frequently used commands.
View, add, submit, delete, retrieve, reset a change file
git help <command> # Show Command's help
Git show # shows the content of a commit git show $id
Git co-<file> # Discard workspace Changes
Git Co. # Discard Workspace Changes
git add <file> # Commit work file changes to local staging area
git Add. # submit all the changed work files to staging area
git rm <file> # Delete files from the version number library
git rm <file>--cached # Delete files from the version number library without deleting the files
git reset <file> # recover from Staging area to working file
git reset--. # Recover from Staging area to working file
git Reset--hard # Restores the state that was recently submitted. Discard all changes made after the last commit
Git ci <file> git ci. Git ci-a # git add, git rm and git ci are all merged together: Tgit Ci-am "some comments"
Git ci--amend # changes the last commit record
git revert < $id > # Restores the state of a commit, and the restore action itself also creates a commit object
git revert HEAD # Restores the state of the last commit
View File diff
git diff <file> # Compare current file and staging area file diff git diff
Git diff < $id 1> < $id the difference between two commits
git diff <branch1>. <branch2> # Compare between two branches
git diff--staged # Compare staging area and version number library differences
git diff--cached # Compare staging area and version number library differences
git diff--stat # only comparative statistics
View Commit Record
git log git log <file> # View the file for each commit record
git log-p <file> # view diff for each specific change
Git log-p-2 # See Diff of two changes in recent times
git log--stat #查看提交统计信息
Tig
You can use TIG instead of diff and Log on your Mac,brew install tig
Git Local Branch Management
View, toggle, create, and delete branches
Git br-r # View Remote Branch
git br <new_branch> # Create a new branch
Git br-v # View the last commit information for each branch
git br--merged # View branches that have been merged into the current branch
git br--no-merged # View branches that have not been merged into the current branch
Git Co <branch> # switch to a branch
Git co-b <new_branch> # Create a new branch and switch to the past
git co-b <new_branch> <branch> # Create a new new_branch based on branch
Git Co $id # Checkout A history commit record, but without branching information, switching to another branch will delete it on its own initiative.
Git co $id-B <new_branch> # Checkout A history commit record. Create a branch
git br-d <branch> # Delete a branch
git br-d <branch> # Force a branch to be removed (a branch that has not been merged must 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 a merge commit
git rebase master <branch> # rebase Master to branch, equivalent to: Git co <branch> && git rebase master && ; Git co master && git merge <branch>
git patch management (for easy development of synchronization on multiple machines)
git diff >: /sync.patch # Generate Patches
git apply. /sync.patch # Patching
git apply--check. /sync.patch #測试补丁是否能成功
Git staging management
Git Stash # Staging
git Stash List # column all stash
git stash apply # recover staged content
git stash Drop # Delete Staging area
GIT Remote branch Management
Git pull # Crawl remote repository All branches updated and merged into local
Git pull--no-ff # crawl remote repository All branches update and merge to local, don't fast-forward merge
Git fetch origin # crawl Remote repository update
git merge Origin/master # merges the remote main branch into the local current branch
Git co--track origin/branch # Tracks a remote branch to create a corresponding local branch
git Co-b <local_branch> origin/<remote_branch> # Creates a local branch based on a remote branch. function Ibid.
Git push # push all branches
Git push Origin Master # pushes the local landlord branch to the remote main branch
Git push-u Origin Master # pushes the local landlord branch to the remote (if no remote Main branch is created). Used to initialize the remote repository)
Git push Origin <local_branch> # Create a remote branch, origin is the remote repository name
Git push Origin <local_branch>:<remote_branch> # Create a remote branch
Git push Origin:<remote_branch> #先删除本地分支 (git br-d <branch>), then push to delete remote branch
GIT Remote repository Management
Git remote-v # View remote server address and warehouse name
git remote Show Origin # View the Server warehouse status
git remote add origin [email protected] Github:robbin/robbin_site.git # Add to Repository Address
git remote set-url origin [email protected] Github.com:robbin/robbin_site.git # Set the remote warehouse address (used to change the remote warehouse address) git remote RM <rep ository> # Deleting a remote repository
Create a remote Warehouse
git clone--bare robbin_site robbin_site.git # Create a version-only warehouse with a project with a version number
Scp-r my_project.git [email protected] git.csdn.net:~ # Upload the repository to the server
mkdir robbin_site.git && cd robbin_site.git && git--bare init # Create a pure warehouse in server
git remote add origin [email protected] Github.com:robbin/robbin_site.git # Set up the repository address
Git push-u Origin Master # client First Commit
Git push-u origin Develop # First submits the local develop branch to the remote develop branch, and the track
git remote Set-head Origin Master # Set the remote repository head to the master branch
can also command settings to trace remote libraries and local libraries
Git branch--set-upstream Master origin/master
GIT branch--set-upstream Develop Origin/develop
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Commands that Git uses frequently