"Reprint" Git common Command collation

Source: Internet
Author: User
Tags file diff

Git Common Command Collation Blog Category:
    • Ubuntu/mac/github/aptana/nginx/shell/linux
Initializing configuration C code
  1. #配置使用git仓库的人员姓名
  2. git config--global user.name "Your name Comes here"
  3. #配置使用git仓库的人员email
  4. git config--global user.email [email protected]
  5. #配置到缓存 default 15 minutes
  6. git config--global credential.helper cache
  7. #修改缓存时间
  8. git config--global credential.helper ' Cache--timeout=3600 '
  9. git config--global color.ui true
  10. git config--global alias.co checkout
  11. git config--global alias.ci commit
  12. git config--global alias.st status
  13. git config--global alias.br branch
  14. git config--global core.editor "Mate-w" # Set editor using TextMate
  15. Git config-1 #列举所有配置
  16. #用户的git配置文件 ~/.gitconfig

view, add, submit, delete, retrieve, reset modified filesC code
  1. git help <command> # Show Command's help
  2. Git show # shows the content of a commit
  3. Git show $id
  4. Git co--<file> # Discard workspace Modifications
  5. Git Co. # Discard Workspace Modifications
  6. git add <file> # Commit working file modifications to local staging area
  7. git Add. # submit all the modified work files to staging area
  8. git rm <file> # remove files from repository
  9. git rm <file>--cached # Remove files from repository without deleting files
  10. git reset <file> # recover from Staging area to working file
  11. git reset--. # Recover from Staging area to working file
  12. git Reset--hard # Restores the state of the last commit, discarding all of the changes since the previous commit
  13. Git ci <file>
  14. Git ci.
  15. Git ci-a # git add, git rm and git ci are all combined together
  16. git ci-am "some comments"
  17. Git ci--amend # Modify the last commit record
  18. git revert < $id > # Restores the state of a commit, and the restore action itself creates a commit object
  19. git revert HEAD # Restores the state of the last commit
View File diffC code
    1. git diff <file> # Compare current file and staging area file differences
    2. Git diff
    3. Git diff < $id 1> < $id 2> # Compare the differences between two commits
    4. git diff <branch1>. <branch2> # Compare between two branches
    5. git diff--staged # compare staging area and repository differences
    6. git diff--cached # compare staging area and repository differences
    7. git diff--stat # just compare statistics

View Commit recordC code
    1. git log
    2. git log <file> # View the file for each commit record
    3. git log-p <file> # view diff for each detail change
    4. Git log-p-2 # See a diff of the last two detailed edits
    5. git log--stat #查看提交统计信息

TIG

You can use TIG instead of diff and Log on your Mac.brew install tig

Get git repository C code
    1. #初始化一个版本仓库
    2. Git init
    3. #Clone远程版本库
    4. git clone [email protected]:wordpress.git
    5. #添加远程版本库origin, syntax for git remote add [shortname] [url]
    6. git remote add origin [email protected]:wordpress.git
    7. #查看远程仓库
    8. Git remote-v

Submit your modified C code
  1. #添加当前修改的文件到暂存区
  2. git Add.
  3. #如果你自动追踪文件, including files that you have manually deleted with a status of deleted
  4. Git add-u
  5. #提交你的修改
  6. git commit–m "your comment"
  7. #推送你的更新到远程服务器, syntax for git push [remote name] [local branch]:[remote branch]
  8. Git push Origin Master
  9. #查看文件状态
  10. git status
  11. #跟踪新文件
  12. git add readme.txt
  13. #从当前跟踪列表移除文件, and completely remove
  14. git rm readme.txt
  15. #仅在暂存区删除, keep files in current directory, no longer track
  16. Git rm–cached readme.txt
  17. #重命名文件
  18. git mv Reademe.txt Readme
  19. #查看提交的历史记录
  20. git log
  21. #修改最后一次提交注释的, using the –amend parameter
  22. git commit--amend
  23. #忘记提交某些修改, the following three commands will only get one commit.
  24. git commit–m &quot;add readme.txt&quot;
  25. git add Readme_forgotten
  26. Git commit–amend
  27. #假设你已经使用git Add, add the modified files A, B to staging area
  28. #现在你只想提交a文件, do not want to submit B file, this should be
  29. git reset HEAD b
  30. #取消对文件的修改
  31. Git checkout–-readme.txt
view, toggle, create, and delete branchesC code
  1. Git br-r # View Remote Branch
  2. git br <new_branch> # Create a new branch
  3. Git br-v # View the last commit information for each branch
  4. git br--merged # View branches that have been merged into the current branch
  5. git br--no-merged # View branches that have not been merged into the current branch
  6. Git Co <branch> # switch to a branch
  7. Git co-b <new_branch> # Create a new branch and switch to the past
  8. git co-b <new_branch> <branch> # Create a new new_branch based on branch
  9. Git Co $id # Checkout A history commit record, but without branching information, switching to another branch will automatically delete
  10. Git co $id-B <new_branch> # Checkout A history commit record and create a branch
  11. git br-d <branch> # Delete a branch
  12. 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 RebaseC code
    1. git merge <branch> # Merge branch branches into the current branch
    2. git merge origin/master--no-ff # do not fast-foward merge so you can generate a merge commit
    3. git rebase Master <branch> # will rebase the master to branch, equivalent to:
    4. Git co <branch> && git rebase master && git co master && git merge <branch>
git patch management (for easy development of synchronization on multiple machines)C code
    1. git diff >: /sync.patch # Generate Patches
    2. git apply. /sync.patch # Patching
    3. git apply--check. /sync.patch #测试补丁能否成功
git staging managementC code
    1. Git Stash # Staging
    2. git Stash List # column all stash
    3. git stash apply # recover staged content
    4. git stash Drop # Delete Staging area
git remote branch managementC code
  1. Git pull # Crawl all branches of remote repository update and merge to local
  2. Git pull--no-ff # Crawl all branches of remote repository update and merge to local, do not fast-forward merge
  3. Git fetch origin # crawl Remote repository update
  4. git merge Origin/master # merges the remote main branch into the local current branch
  5. Git co--track origin/branch # Track a remote branch to create the appropriate local branch
  6. git co-b <local_branch> origin/<remote_branch> # Create local branch based on remote branch, same as above
  7. Git push # push all branches
  8. Git push Origin Master # pushes the local landlord branch to the remote main branch
  9. 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)
  10. Git push Origin <local_branch> # Create a remote branch, origin is the remote repository name
  11. Git push Origin <local_branch>:<remote_branch> # Create a remote branch
  12. Git push Origin:<remote_branch> #先删除本地分支 (git br-d <branch>), then push to delete remote branch

Basic Branch Management C code
  1. #创建一个分支
  2. Git branch iss53
  3. #切换工作目录到iss53
  4. Git chekcout iss53
  5. #将上面的命令合在一起, create a iss53 branch and switch to ISS53
  6. Git chekcout–b iss53
  7. #合并iss53分支, the current working directory is master
  8. git merge iss53
  9. #合并完成后, no conflicts, delete iss53 branch
  10. Git branch–d iss53
  11. #拉去远程仓库的数据, syntax for git fetch [remote-name]
  12. git fetch
  13. #fetch will pull up the latest remote repository data, but will not automatically merge to the current directory
  14. Git pull
  15. #查看远程仓库的信息
  16. git remote show origin
  17. #建立本地的dev分支追踪远程仓库的develop分支
  18. git checkout–b Dev origin/develop
git remote repository managementC code
    1. Git remote-v # View remote server address and warehouse name
    2. git remote Show Origin # View the Server warehouse status
    3. git remote add origin [email protected] Github:robbin/robbin_site.git # Add repository Address
    4. 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)
    5. Git remote rm <repository> # Delete a repository
Create a remote warehouseC code
  1. git clone--bare robbin_site robbin_site.git # Create a version-only warehouse with a versioned project
  2. Scp-r my_project.git [email protected] git.csdn.net:~ # Upload the repository to the server
  3. mkdir robbin_site.git && cd robbin_site.git && git--bare init # Create a pure warehouse on the server
  4. git remote add origin [email protected] Github.com:robbin/robbin_site.git # Set up the repository address
  5. Git push-u Origin Master # client First Commit
  6. Git push-u origin Develop # First submits the local develop branch to the remote develop branch, and the track
  7. git remote Set-head Origin Master # Set the remote repository head to the master branch
You can also command settings to trace the remote library and the local library C code
    1. Git branch--set-upstream Master origin/master
    2. GIT branch--set-upstream Develop Origin/develop

"Reprint" Git common Command collation

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.