Git Cheat Sheet 中英譯(十九)
一、常用命令:
1.建立
① 克隆現有的儲存庫 :Clone an existing repository
1 | $ git clone ssh://[email protected]/repo.git
② 建立一個新的本地倉庫 :Create a new local repository (初始化)
1 | $ git init
2.本地更改
① 更改工作目錄中的檔案:Changed files in your working directory (檢視狀態)
1 | $ git status
② 對跟蹤檔案的更改:Changes to tracked files (檢視修改內容)
1 | $ git diff
③ 向下一個提交新增所有當前更改:Add all current changes to the next commit (新增所有檔案)
1 | $ git add .
2 | $ git add *.html 表示新增所有html格式的檔案
④ 將<file>中的一些更改新增到下一個提交中:Add some changes in <file> to the next commit
1 | $ git add -p <file>
⑤ 提交跟蹤檔案中的所有本地更改:Commit all local changes in tracked files
1 | $ git commit -a
⑥ 提交以前階段的更改:Commit previously staged changes
1 | $ git commit
⑦ 更改最後一次提交,不要修改釋出的提交!:Change the last commit ,Don‘t amend published commits!
1 | $ git commit --amend
3.提交歷史
① 顯示所有提交,從最新開始:Show all commits, starting with newest
1 | $ git log
② 顯示特定檔案隨時間的變化:Show changes over time for a specific file
1 | $ git log -p <file>
③ 誰在<file>中更改了什麼和什麼時間:Who changed what and when in <file>
1 | $ git blame <file>
4.分支和標籤
① 列出所有現有分支:List all existing branches
1 | $ git branch -av
② 切換分支機構負責人:Switch HEAD branch
1 | $ git checkout <branch>
③ 建立一個基於分支的新分支,在你當前的頭(主分支):Create a new branch based on your current HEAD
1 | $ git branch <new-branch>
④ 根據以下內容建立一個新的跟蹤分支在遠端分支:Create a new tracking branch based on a remote branch
1 | $ git checkout --track <remote/branch>
⑤ 刪除本地分支:Delete a local branch
1 | $ git branch -d <branch>
⑥ 用標記,標記當前提交:Mark the current commit with a tag (打標籤)
1 | $ git tag <tag-name>
5.更新和釋出
① 列出所有當前配置的遠端主機:List all currently configured remotes (檢視遠端庫的資訊)
1 | $ git remote -v
② 顯示關於遠端的資訊:Show information about a remote
1 | $ git remote show <remote>
③ 新增新的遠端倉庫,名為<remote>:Add new remote repository, named <remote>
1 | $ git remote add <shortname> <url>
④ 從 <remote> 下載所有更改,但不要和HEAD合併 :Download all changes from <remote> , but don‘t integrate into HEAD
1 | $ git fetch <remote>
⑤ 下載更改,並直接下載,合併/融入頭:Download changes and directly merge/integrate into HEAD
1 | $ git pull <remote> <branch>
⑥ 在遠端上釋出本地更改:Publish local changes on a remote
1 | $ git push <remote> <branch>
⑦ 刪除遠端上的一個分支:Delete a branch on the remote
1 | $ git branch -dr <remote/branch>
⑧ 釋出你的標籤:Publish your tags
1 | $ git push --tags
六.合併和變基
① 將 <branch> 合併到當前頭(指向、分支)中:Merge <branch> into your current HEAD (合併分支)
1 | $ git merge <branch>
② 將當前頭重設為<branch>,不要重新基礎釋出提交!:Rebase your current HEAD onto <branch>,Don‘t rebase published commits!
1 | $ git rebase <branch>
③ 中止一個變基:Abort a rebase
1 | $ git rebase --abort
④ 在解決衝突後繼續重建基地 :Continue a rebase after resolving conflicts
1 | $ git rebase --continue
⑤ 使用已配置的合併工具,解決衝突:Use your configured merge tool to solve conflicts
1 | $ git mergetool
⑥ 使用編輯器手動解決衝突並且(在解析之後)標記檔案為已解析
:Use your editor to manually solve conflicts and (after resolving) mark file as resolved
1 | $ git add <resolved-file>
2 | $ git rm <resolved-file>
7.撤銷(undo)
① 在工作目錄中放棄所有本地修改:Discard all local changes in your working directory
1 | $ git reset --hard HEAD
② 丟棄特定檔案中的本地更改:Discard local changes in a specific file
1 | $ git checkout HEAD <file>
③ 通過生成新的提交來恢復提交(相反的變化):Revert a commit (by producing a new commit with contrary changes)
1 | $ git revert <commit>
④ 在解決衝突後繼續重建基地,然後丟棄從那時起的所有更改
:Reset your HEAD pointer to a previous commit and discard all changes since then
1 | $ git reset --hard <commit>
⑤ 將所有更改保留為無階段更改變化:and preserve all changes as unstaged changes
1 | $ git reset <commit>
⑥ 儲存未提交的本地更改 :and preserve uncommitted local changes
1 | $ git reset --keep <commit>