Common Git Commands

Source: Internet
Author: User
Tags file diff git commands

View, add, submit, delete, retrieve, reset modified files

git help <command> # Show Command's help

Git show # shows the content of a commit git show $id

Git co--<file> # Discard workspace Modifications

Git Co. # Discard Workspace Modifications

git add <file> # Commit working file modifications to local staging area

git Add. # submit all the modified work files to staging area

git rm <file> # remove files from repository

git rm <file>--cached # Remove files from repository without deleting 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 of the last commit, discarding all of the changes since the previous commit

Git ci <file> git ci. Git ci-a # git add, git rm and git ci are all combined to make git ci-am "some comments"

Git ci--amend # Modify 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 <id1>< id1>< id2> # Compare differences between commits two times

git diff <branch1>. <branch2> # Compare between two branches

git diff--staged # compare staging area and repository differences

git diff--cached # compare staging area and repository differences

git diff--stat # just compare statistics

View Commit Record

git log git log <file> # View the file for each commit record

git log-p <file> # view diff for each detail change

Git log-p-2 # See a diff of the last two detailed edits

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 automatically delete

Git co $id-B <new_branch> # Checkout A history commit record and create a branch

git br-d <branch> # Delete a branch

git br-d <branch> # Force a branch to be removed (the branch that is not merged is removed when it needs to be forced)

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 all branches of remote repository update and merge to local

Git pull--no-ff # Crawl all branches of remote repository update and merge to local, do not 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 # Track a remote branch to create the appropriate local branch

git co-b <local_branch> origin/<remote_branch> # Create local branch based on remote branch, same as above

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 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

GitHub

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 repository Address

git remote set-url origin [email protected] Github.com:robbin/robbin_site.git # Set the remote warehouse address (used to modify 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 versioned project

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 on the 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

You can also command settings to track remote libraries and local libraries

Git branch--set-upstream Master origin/master

GIT branch--set-upstream Develop Origin/develop

Common Git Commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.