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>

 

猜你喜欢

转载自blog.csdn.net/qq_40415721/article/details/83685548