[关闭]
@gump88 2016-07-25T07:20:09.000000Z 字数 1105 阅读 970

Git常用命令使用总结

git


git是一款免费、开源的分布式版本控制系统,由大神Linus开发,用来管理Linux内核的开发过程,但是随后就流行开来,越来越多的人开始使用git来管理项目。本文主要记录常用的git命令,些许会涉及到git的原理。

0. git环境配置

  1. git config --global user.name ""
  2. git config --global user.email ""

1. git remote

增加远程仓库

  1. git remote add <name> <url>

显示所有远程仓库

  1. git remote -v

重设某个远程仓库的地址

  1. git remote set-url <name> <newurl>

删除某个远程仓库

  1. git remote remove <name>

2. git add

增加所有文件

  1. git add -A

增加某个文件

  1. git add <filename>

3. git commit

添加提交信息

  1. git commit -m <message>

提交所有修改

  1. git commit -m <message> -a

提交单个修改

  1. git commit -m <message> <filename>

4. git pull

git pull和git fetch的区别主要是git pull会自动合并,而git fetch不会自动合并,需要手动merge。

  1. git pull <remote> <master>

5. git push

  1. git push <remote> <master>

6. git reset

git reset命令常用来将当前版本回退到指定版本
一般先使用git reflog查看历史版本,然后通过git reset回退到指定版本

  1. git reset --hard HEAD@{0}

7. git clone

当本地目前没有git repository时,采用git clone可以将remote的整个仓库都clone下来,用法如下:

  1. git clone <url>

8. git diff

9. git fetch

从远程获取最新版本到本地,不会自动merge,相比较git pull而言需要手动merge,但是更安全一点。

  1. git fetch <remote> <respository>

10. git rebase

git rebase的用途可以参考http://gitbook.liuhui998.com/4_2.html。我的简单理解就是,当主分支和当前分支都在某一个版本上发生了改动,那么git rebase将本地分支的改动作为补丁保存下来,然后将补丁更新到主分支。可以这样看git merge有一个分叉的过程,而git rebase是一个线性的过程。

  1. git rebase <branch>

最后放一张来自http://www.cnblogs.com/1-2-3/的git图,

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注