我 Git 命令列表 (1)【转】

简介: 转自:http://www.microsofttranslator.com/bv.aspx?from=en&to=zh-CHS&a=http%3A%2F%2Fvincenttam.github.io%2Fblog%2F2014%2F06%2F16%2Fmy-git-command-list-1%2F 因为我的记忆力差长期在命令中,我会写下我知道的Git命令。

转自:http://www.microsofttranslator.com/bv.aspx?from=en&to=zh-CHS&a=http%3A%2F%2Fvincenttam.github.io%2Fblog%2F2014%2F06%2F16%2Fmy-git-command-list-1%2F

因为我的记忆力差长期在命令中,我会写下我知道的Git命令。

此列表是为我引用写的。因此,我不会包括一切。我要去写一些基本的东西,所以,如果我忘记了它,我可以查看它。如果你想要的命令的详细的解释,而是找到文档。如果您遇到了一个问题,使用 Git,最好的老师是,一般情况下,一个搜索引擎。

初始设置

请参阅Pro Git节 1.5.

我推荐新的 Git 用户设置的配置变量push.default使用git config--global选项,让 Git 保存中的变量~/.gitconfig以避免在这里所示的警告.1由于我有限的了解 Git,我找不到的方式来禁止显示警告后阅读的堆栈溢出的问题。我终于搞明白了阅读的中国的博客,发现在第一个脚注之后。

初始化存储库

$ git init
$ git init --bare

第一,它是用于存储库,其中包含的源代码的常用命令。第二个,它可以用于在远程服务器上。2

注意:"运行git init在现有的存储库是安全的。3

克隆存储库

看到临 Git的第 2.1 节.

这里,我知道一个可以传递--bare选项git clone.

$ git clone --bare repo.old repo

在上述命令中,repo.old是一个旧的存储库,和一个创建新的裸存储库repo从那老非裸存储库。

从远程资源库得到东西

有基本的命令:git pullgit fetchgit merge.大体说来,第一个是"总和"的以下两个。

$ git fetch           # fetch from origin/upstream
$ git fetch host      # fetch all branches from remote "host"
$ git fetch host foo  # fetch branch "foo" from remote "host"

注意: 在上面的代码块,pull可以代替pull.

其实合并分支之前, 我们能先看一下他们之间的分歧。

查看差异

我只知道git diff.

基本用法

如果你写的东西和尚未提交您的更改,则可以签发git diff在终点,看您未提交的更改和最新提交的区别。-代表老的承诺的内容而+表示更新未提交的更改。

比较旧属同一分支中支一角

只追加 40 位数 sha-1 哈希的交托的头七位数git diff会做。

比较的分支机构

我发现在官方的参考页。(URL)<1>窗体工作好则origin/sourceoctoress/linklog~/octopress.然而,我还没完全理解此命令。

$ git diff origin/source source
fatal: ambiguous argument 'source': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(添加在 2014 年 8 月 7 日)

现在我知道如何更正上面的 Git 命令。指我更新的帖子在 Git Diff 双连字符.


添加删除文件

有三个基本的命令:

  • git add
  • git mv
  • git rm

看到这里之间的差异git add -Agit add ..

$ git add <file>...             # Add <file> to the staging area
$ git add .                     # Add all modified/new files that are tracked
$ git add -A                    # The '-A' flag stands for "all"
$ git mv <file> <new dir/path>  # move the file and record the action in Git
$ git rm <file>                 # delete a file and record the action in Git

我读过解释的区别简化中国博客git rmrm. (URL)

你可能会包括一些未跟踪的文件中.gitignore所以,这些文件将被忽略的 Git。

提交更改

唯一的命令是git commit.有一个可以使某些基本选项使用。

  • -a(又称--all): 提交的所有跟踪文件的更改。
  • --amend: 更改提示工作分支的提交消息。
  • -m <msg>(又称--message): 直接输入提交消息。

如果-m使用标志,然后编辑器窗口,被调用。在编辑器窗口,其中包含提交消息,第一行是标题中提交,而第二行应该留为空白。后续的行,是始于#是提交消息的内容。

如果你想恢复git commit --amend您可以参考我之前的帖子.

还原更改

对我来说,它是这篇文章的最重要组成部分。知道两个命令为这种类型的任务。

$ git reset HEAD <file>...   # unstage <file>
$ git reset HEAD --soft      # unstage all uncommitted chanages without changing the file(s)
$ git reset HEAD --hard      # revert the files to the latest commit
$ git checkout -- <file>...  # undo all uncommitted changes to <file>

使用分支

我知道这是一项重要功能的 Git,,但不要,很多时候现在,所以我只是包括一些简单的命令在这里。

$ git branch                 # list all branches, excluding the remote ones
$ git branch --list          # same as above
$ git branch -a              # list all branches, including the remote ones
$ git branch foo             # create `foo' branch from the current one
$ git checkout foo           # switch to `foo' branch from the current one
$ git checkout -b foo        # the "sum" of the above two commands
$ git branch -d foo          # delete `foo' branch
$ git checkout --orphan foo  # create a new orphan branch named `foo'

当我开始使用 Octopress,我并不熟悉 Git。因此,我搞砸了处理分支和这个博客我 Git 仓库的网络图的命令。

显示历史记录

还有一种 GUI 方式这样做。

$ git show    # Show the diff hunks of recent commits
$ git log     # Show the commits without diff hunks
$ git log -6  # Show the 6 most recent commits
$ git log -p  # Show the commits with diff hunks

没有-p国旗,git log将显示用户的名称和电子邮件,时间、 沙 1 哈希、 头和每次提交的内容但diff hunk(s)。浏览通过提交在关键的动作git log是类似于那些在less实用程序。如果指定的提交并不是数量,一个可以通过滚动到底部浏览整个提交历史。

你可以使用git show若要设置格式的输出,但也没学到的。

盼望写第二个列表,但我认为我可以在未来几个月。

一些题外话东西

gitk

一个可以调用gitk这是一个 GUI 工具用于查看显示历史的 Git 提交,如果他/她想学的上述部分中的命令。

fugitive.vim

(编辑在 2016 年 2 月 9 日)

fugitive.vim是一个伟大的 Vim 插件。

:Gst[atus]      # Show the `git status' on a horizontal split window
:Git <command>  # Equivalent to `:!git <command>'
:Glog           # Show commits of the current file in a quickfix list
:Gllog          # Show commits of the current file in a location list
:Glog --        # Show all commits of the current branch as diff hunks
:Glog -- %      # Show all commits containing the current file as diff hunks
:Glog -- foo    # Show all commits containing the file `foo' as diff hunks

知道的使用:Glog.

Gstatus您可以方便地添加/删除文件从临时区域。

  • <C-n><C-p>分别跳转到的下一页和上一页的文件。
  • cc对于 Git commit。
  • g?调用可以在中使用的键映射列表:Gstatus帮助窗口。
  • D就像是git diff但与布局vimdiff.默认情况下,一个窗口是在另一个上面。
  • dv就像是D但一个窗口是对他人的权利。
【作者】 张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
目录
相关文章
|
1月前
|
开发工具 git
|
8月前
|
开发工具 git
Git标签命令
Git标签命令
37 0
|
8月前
|
开发工具 git
Git的文件命令
Git的文件命令
73 0
|
9月前
git--分支重命名操作
git--分支重命名操作
222 0
|
开发工具 git
git 命令怎么创建新分支?
git 命令怎么创建新分支?
307 0
git 命令怎么创建新分支?
|
开发工具 git
git 命令怎么删除本地分支
git 命令怎么删除本地分支
159 0
git 命令怎么删除本地分支
|
开发工具 git
git 命令怎么删除远程分支
git 命令怎么删除远程分支
166 0
git 命令怎么删除远程分支
|
开发工具 git
【Git&GitHub - 10】:Git创建、切换、删除分支
【Git&GitHub - 10】:Git创建、切换、删除分支
126 0
【Git&GitHub - 10】:Git创建、切换、删除分支
|
存储 缓存 开发工具
Git日常使用命令记录
日常使用git命令记录,便于回忆查看和使用。。。
|
开发工具 git
Git - 自定义Git之配置别名
Git - 自定义Git之配置别名
99 0
Git - 自定义Git之配置别名

热门文章

最新文章

相关实验场景

更多