Git命令大全(Github)

SSBun發表於2017-12-13

CREAT(建立)

git init                                      在當前目錄下建立一個本(Create a new local repository)

git clone  ssh://user@domain.tld/repo.git     在遠端庫克隆一個本地庫(Clone an existing repository)

Configuration(配置)

git config [--global] user.name       設定提交時附帶的名字(Set the name attached to all your commits)

git config [--global] user.email        設定提交時附帶的email(Set the email attached to all your commits)

git config --global color.ui auto       設定命令列輸出回執的顏色(Set colorzition of  command line output for all repos)

git config [--global] user.name         獲取當前庫設定的使用者名稱(Print set name(in current repository or globally))

git config [--global] user.email        獲取當前庫設定的email(Print set email(in current repository or  globally))

Local Changes(本地操作)

git status    檢視工作區內的檔案修改(List changed files in your working directory)

git diff       檢視已追蹤檔案的修改(List changed to tracked files)

git add       新增此檔案的所有修改在下次提交時(Add all current changed in file to the next commit)

git add .     新增本地庫中的所有修改在下次提交的時(Add all current changed to the next commit)

git mv          修改檔名並新增到下次提交當中(Rename file and add it to next commit)

git rm          刪除此檔案並將此處刪除新增到下次提交當中(Delete file and add its deletion to next commit)    

git commit -a          提交工作區所有檔案(Commit all local changes in tracked files)

Commit History(提交歷史)

git log                                             顯示所有的提交日誌(Show all commits)

git log -p                                       這個檔案的最後一次提交日誌(Shwo changes over time for a specific file)

git log --author=<committer name>  這個提交者最後一次的提交日誌(Show changes over time for a specific committer)

git blame <file>                              此檔案被誰修改了(Who changed what and when in file)

git stash                                           檢視臨時的檔案變動 (Store changes temporarily)

git stash pop                                    刪除上一次記錄儲蓄新的改動記錄(Remove and apply changes)

git rm --cached <file>                  把此檔案從過去的提交記錄中刪除但是保留當前本地的檔案(Remvoe file from previous commits but keep it locally)

Branches & Tags(分支和標籤)

git branch                                 本地所有的分支列表(List all existing branches)

git checkout <branch>            切換分支(Switch HEAD branch)

git branch <new branch>        建立新分支(Creat a new branch based on your current HEAD)

git branch --track <new-branch><remote-branch>  建立一個新的分支基於一個遠端的分支(Creat a new  tracking branch based on a remote branch)

git branch -d <branch>                          刪除一個本地分支(Delete a local branch)

git branch origin --delete <branch>       刪除一個遠端分支(Delete a remote branch)

git push <remote> : <old name>     重新命名遠端分支名(Rename a branch on remote)git push

 git push <remote> <new name>           

git tag <tag-name>       給當前提交打一個tag,也可以檢視當前標籤(Tag the current commit)

Update & Publish(更新和提交)

git remote -v                         檢視遠端庫的地址列表(List all currently configured remotes)

git remote show <remote>       檢視這個遠端庫的資訊(Show information about a remote)

git remote add <remote> <url> 新增新的遠端庫(Add new remote repository)

git remote rename <old-name> <new-name>    重新命名遠端庫(Rename a remote)

git fetch <remote>       從遠端庫更新所有的資訊到本地,但是不合並(Download all changes from remote,but don't merge into HEAD)

git fetch -p <remote>     從遠端庫更新所有的資訊到本地,但是不合並並清理已刪除的遠端分支(Download all changes fromm remote,but don't merge in HEAD and clean up deleted branchs from origin)

git pull <remote><branch>   從遠端庫更新資料並立即合併資料(Download changes and directly merge into HEAD)

git push <remote><branch>   將本地資料同步到遠端庫中(Publish local changes on a remote)

git remote add --track <remote-branch><remote><url>  追蹤一個遠端庫(Track a remote repository)

git push --tags                         同步標籤到遠端庫(Publish your tags

git remote show <remote>      顯示遠端庫資訊(Show information about a submodule)

Merge & Rebase(分支合併和重整資料)

git merge <branch>       將其他分支和併到當前分支(Merge branch into your current HEAD)

git rebase <branch>          將親她分支合併到當前分支並按照提交順序排序(Rebase your current HEAD onto branch)

git rebase --abort             終止當前合併(Abort a rebase)

git rebase --continue       解決衝突後繼續當前合併和重整(Continue a rebase after resolving confilcys)

git mergetool                      使用配置的合併工具解決衝突(Resolve conflicts using your configured merge tool)

git add <resolved-file>     手動解決衝突使用編輯器並標記已解決的檔案

git rm <resolved-file>

Undo(撤銷)

git reset --hard HEAD                丟棄所有的本地修改(Discard all local changes in your working directory)

git checkout HEAD <file>           丟棄此檔案的本地修改(Discard local changes in a specific file)

git revert  <commit>                  撤銷某次的提交內容(Revert a commit by providing a new commit with contrary changes)

git checkout <commit><file>    撤銷某次提交的某個檔案的內容(Revert a specific file from a previous commit)

重置頭指標到過去的某個提交上,版本回退(Reset your HEAD pointer to a previous commit)

git reset --hard  <commit>     回退到某個版本(Discarding local changes)

git reset <commit>                   回退到某個版本並儲存未追蹤的改動

git reset --keep <commit>       回退到某個版本並儲存未提交的改動

相關文章