git 基础

一、取消
1、覆盖提交
第一次提交commit之后,发现还有东西没有提交,想要合入到一个commit里面,可以如下操作:

$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend

2、取消暂存的文件
当使用git add *
可以使用 git reset HEAD ... 来取消暂存
3、撤销对文件的修改(reset和checkout的区别)
如果你并不想保留对 CONTRIBUTING.md 文件的修改,想把它还原成上次提交的样子
git checkout -- CONTRIBUTING.md
git checkout -- [file]相当于相当于拷贝了另一个文件来覆盖它,不可还原
二、远程仓库
1、查看远程仓库 git remote 服务器会列出来远程仓库的名称,也可以加-v查看对应的URL

$ git remote
origin

$ git remote -v
origin  https://github.com/schacon/ticgit (fetch)
origin  https://github.com/schacon/ticgit (push)

2、从远程仓库中抓取与拉取

$ git fetch [remote-name]

我一般喜欢用 git fetch --all

3、查看远程仓库的信息
$ git remote show origin
可以查看到远程的源、远程分支,本地分支和远程分支的对应
4、远程仓库的移除与重命名
git remote rename 旧名称 新名称
三、tag
1、git tag 列出该仓库的所有tag
2、查看某个tag的信息
git show tag
3、上传 git push origin --tags
四、别名
因为很多命令名称还是挺长的,当打的很快的时候不是很方便,这个时候我们就可以考虑给git起一些别名

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status

当我们要输入git commit的时候 ,只需要输入git ci
再举两个简单的例子

$ git config --global alias.unstage 'reset HEAD --'

那么以下的两个命令等价

$ git unstage fileA
$ git reset HEAD -- fileA

为了看起来更清楚一些,通常也会添加一个last命令
$ git config --global alias.last 'log -1 HEAD'
这样,可以轻松地看到最后一次提交:

$ git last
commit 66938dae3329c7aebe598c2246a8e6af90d04646
Author: Josh Goebel 
Date:   Tue Aug 26 19:48:51 2008 +0800

    test for current head

    Signed-off-by: Scott Chacon 

你可能感兴趣的:(git 基础)