转自: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但一个窗口是对他人的权利。

我 Git 命令列表 (1)【转】的更多相关文章

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

    转自:http://www.microsofttranslator.com/bv.aspx?from=en&to=zh-CHS&a=http%3A%2F%2Fvincenttam.gi ...

  2. 关于常用的git命令列表

    我博客园中所写的git内容几乎都是看的蒋鑫老师的<git权威指南>这本书实在太好了. 常用的Git命令. git add  添加到暂存区 git add interactive  交互式添 ...

  3. 常look的Git命令

    常用的Git命令   命令  简要说明 git add 添加至暂存区 git add–interactive 交互式添加 git apply   应用补丁 git am  应用邮件格式补丁 git a ...

  4. Git命令行(转用于学习和记录)

    Git命令行介绍和使用说明(持续更新) 参见:<Git 中文简体教程> 一. 命令“git”或者“git help”查询常用命令 [add]: “git add”——不但是用来添加不在版本 ...

  5. Git命令详解

    一个中文git手册:http://progit.org/book/zh/ 原文:http://blog.csdn.net/sunboy_2050/article/details/7529841 前面两 ...

  6. Git 命令速查表

    Git 命令速查表 1.常用的Git命令 命令 简要说明 git add 添加至暂存区 git add-interactive 交互式添加 git apply 应用补丁 git am 应用邮件格式补丁 ...

  7. git命令实战之血泪记录

    注意: 本文章所写所有命令均在Git命令行窗口执行!非cmd窗口! 打开git命令行窗口步骤为:到项目根目录下执行bash命令行操作:右键点击Git Bash Here菜单,打开git命令窗口,不是c ...

  8. 一天工作所用到的Git命令

    一天工作所用到的Git命令 像大多数新手一样,我一开始是在网上搜索 Git 命令,然后把答案复制粘贴,并没有真正理解它们究竟做了什么. 后来我曾经想过:"如果有一个最常见的 Git 命令的列 ...

  9. git命令的理解与扩展

    Git的模式如图: Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Repository:仓库区(或本地仓库) 一.新建代码库 # 查看gi ...

随机推荐

  1. 设计模式 --深入理解javascript

    /* 一.单例模式 */ var Universe; (function () { var instance; Universe = function Universe() { if (instanc ...

  2. 自己学习编程时间比较短,现在把一下自己以前刚刚接触C++时的程序上传一下,有空可以看看

    键盘输入十个数,找出最大值和最小值. #include<iostream.h>void main (){int a[10];int i,t,max,min;cout<<&quo ...

  3. poj 2711 Leapin' Lizards && BZOJ 1066: [SCOI2007]蜥蜴 最大流

    题目链接:http://poj.org/problem?id=2711 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1066 Your p ...

  4. ios读取通讯录信息

    ios读取通讯录信息 (2012-05-22 14:07:11) 标签: ios读取通讯录 it   iphone如许app读取通讯录信息,读取通讯录信息时需要加载AddressBookUI 和Add ...

  5. CREATEINPUTLAYOUT_INCOMPATIBLEFORMAT

    这个error的全称是这样的 D3D11 ERROR: ID3D11Device::CreateInputLayout: Element[1]'s format (UNKNOW) cannot be ...

  6. 利用WiFi钓鱼法追邻居漂亮妹纸

    假设,你的邻居是一个妹纸.漂亮单身,你,技术狗,家穷人丑,集体户口.像借酱油这种老套搭讪方式的成功率对你来说实在很低. 你要做的是了解她,然后接近她.通过搜集更多的情报,为创造机会提供帮助. 初级情报 ...

  7. 一道PK赛题

    Problem Description I think that you might have played the traditional Chinese ring game: The Chines ...

  8. SOA之(3)——面向服务计算基础

    面向服务计算基础(Service-Oriented Computing Fundamentals) 面向服务的计算(Service-Oriented Computing) 面向服务的计算是一个伞状术语 ...

  9. 如何快速查看将C反汇编的代码

    查看反汇编主要的思路在于将 流程,处理,算法 区分开来.1 函数调用:原C代码: int sum(int, int);int main(){ int c = sum(1, 2); printf(&qu ...

  10. BZOJ2199: [Usaco2011 Jan]奶牛议会

    趁此机会学了一下2-SAT. 以前的2-SAT都是用并查集写的,只能应用于极小的一部分情况,这次学了一正式的2-SAT,是用一张有向图来表示其依赖关系. 2-SAT的介绍参见刘汝佳<训练指南&g ...