前言
git 作为易用,强大的代码管理工具博大精深,各种专门介绍其使用的书籍也相当多,本文只是记录一些个人比较常用的一些。
1. git log & git log --name-status |
2. git show |
3. git config |
Tips
1.git log & git log --name-status
查看历史记录,以前一直使用git log,但是这个命令默认情况下只能显示出一个简短的commit信息,对本次更改涉及的文件并不会显示出来,我们可以加上--name-staus的命令参数使得其输出更加详细的信息:
git log commit 50e1fe0f7df210aec464499eaf6567466513e00f fix xxxxxxxxxx |
git log -name-status commit 50e1fe0f7df210aec464499eaf6567466513e00f fix xxxxxxxxxx M project/helloworld/A.java D project/helloworld/B.java M project/helloworld/C.java |
2. git show
如果需要看更加详细的某次改动的具体代码,就可以使用这个命令,后面跟上commit id:
git show 50e1fe0f7df210aec464499eaf6567466513e00f commit 50e1fe0f7df210aec464499eaf6567466513e00f fix xxxxxxxxxx diff --git a/project/helloworld/A.java b/project/helloworld/A.java index 65f5257..6cfbe07 100755 @@ -1,8 +1,5 @@ |
3. gitconfig
git配置和alias配置,经常输入单词有时会比较繁琐,所以配置别名可以使得输入更加便捷,下面的几个别名也是从网上收集而来:
[user] name = Your NAME email = yourname@gmail.com [alias] ci = commit co = checkout st = status br = branch [color] status = auto ui = auto diff = auto branch = auto interactive = auto [core] autocrlf = input |
2013-08-26
3. git push -f
用于强制更行remote分支,-f为force。当本地做了几次commit后比如commit a----->commit b----->commit c;然后push到了远程分支,突然发现commit c不需要了,这个时候本地我们可以reset到commit b的状态或直接checkoutcommit b,然后把当前的分支重新push到远程那个分支;
git log commit 50e1fe0f7df210aec464499eaf65674668902s1830ef fix a commit 50e1fe0f7df210aec464499eaf6567466ce513e00f fix b commit 50e1fe0f7df210aec464499eaf6567466513e21300f fix c git co -b revert_c 50e1fe0f7df210aec464499eaf6567466ce513e00f git push -u -f origin revert_c:remote_x |