Git Common Command Collation
Blog Category:
- Ubuntu/mac/github/aptana/nginx/shell/linux
Initializing configuration C code
- #配置使用git仓库的人员姓名
- git config--global user.name "Your name Comes here"
- #配置使用git仓库的人员email
- git config--global user.email [email protected]
- #配置到缓存 default 15 minutes
- git config--global credential.helper cache
- #修改缓存时间
- git config--global credential.helper ' Cache--timeout=3600 '
- git config--global color.ui true
- git config--global alias.co checkout
- git config--global alias.ci commit
- git config--global alias.st status
- git config--global alias.br branch
- git config--global core.editor "Mate-w" # Set editor using TextMate
- Git config-1 #列举所有配置
- #用户的git配置文件 ~/.gitconfig
view, add, submit, delete, retrieve, reset modified filesC code
- 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 together
- 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 creates a commit object
- git revert HEAD # Restores the state of the last commit
View File diffC code
- git diff <file> # Compare current file and staging area file differences
- Git diff
- Git diff < $id 1> < $id 2> # Compare the differences between two commits
- 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 recordC code
- 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
Get git repository C code
- #初始化一个版本仓库
- Git init
- #Clone远程版本库
- git clone [email protected]:wordpress.git
- #添加远程版本库origin, syntax for git remote add [shortname] [url]
- git remote add origin [email protected]:wordpress.git
- #查看远程仓库
- Git remote-v
Submit your modified C code
- #添加当前修改的文件到暂存区
- git Add.
- #如果你自动追踪文件, including files that you have manually deleted with a status of deleted
- Git add-u
- #提交你的修改
- git commit–m "your comment"
- #推送你的更新到远程服务器, syntax for git push [remote name] [local branch]:[remote branch]
- Git push Origin Master
- #查看文件状态
- git status
- #跟踪新文件
- git add readme.txt
- #从当前跟踪列表移除文件, and completely remove
- git rm readme.txt
- #仅在暂存区删除, keep files in current directory, no longer track
- Git rm–cached readme.txt
- #重命名文件
- git mv Reademe.txt Readme
- #查看提交的历史记录
- git log
- #修改最后一次提交注释的, using the –amend parameter
- git commit--amend
- #忘记提交某些修改, the following three commands will only get one commit.
- git commit–m "add readme.txt"
- git add Readme_forgotten
- Git commit–amend
- #假设你已经使用git Add, add the modified files A, B to staging area
- #现在你只想提交a文件, do not want to submit B file, this should be
- git reset HEAD b
- #取消对文件的修改
- Git checkout–-readme.txt
view, toggle, create, and delete branchesC code
- 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 RebaseC code
- 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> # will rebase the 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)C code
- git diff >: /sync.patch # Generate Patches
- git apply. /sync.patch # Patching
- git apply--check. /sync.patch #测试补丁能否成功
git staging managementC code
- Git Stash # Staging
- git Stash List # column all stash
- git stash apply # recover staged content
- git stash Drop # Delete Staging area
git remote branch managementC code
- 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
Basic Branch Management C code
- #创建一个分支
- Git branch iss53
- #切换工作目录到iss53
- Git chekcout iss53
- #将上面的命令合在一起, create a iss53 branch and switch to ISS53
- Git chekcout–b iss53
- #合并iss53分支, the current working directory is master
- git merge iss53
- #合并完成后, no conflicts, delete iss53 branch
- Git branch–d iss53
- #拉去远程仓库的数据, syntax for git fetch [remote-name]
- git fetch
- #fetch will pull up the latest remote repository data, but will not automatically merge to the current directory
- Git pull
- #查看远程仓库的信息
- git remote show origin
- #建立本地的dev分支追踪远程仓库的develop分支
- git checkout–b Dev origin/develop
git remote repository managementC code
- 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 <repository> # Delete a repository
Create a remote warehouseC code
- 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 trace the remote library and the local library C code
- Git branch--set-upstream Master origin/master
- GIT branch--set-upstream Develop Origin/develop
"Reprint" Git common Command collation