git tips

前言

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
Author: badlogic <badlogic@gmail.com>
Date: Mon Aug 26 11:00:07 2013 +0800

fix xxxxxxxxxx

 

git log -name-status

commit 50e1fe0f7df210aec464499eaf6567466513e00f
Author: badlogic <badlogic@gmail.com>
Date: Mon Aug 26 11:00:07 2013 +0800

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
Author: badlogic <badlogic@gmail.com>
Date: Mon Aug 26 11:00:07 2013 +0800

fix xxxxxxxxxx

diff  --git a/project/helloworld/A.java b/project/helloworld/A.java

index 65f5257..6cfbe07 100755
--- a/project/helloworld/A.java
+++ b/project/helloworld/A.java

@@ -1,8 +1,5 @@
package com.badlogic.activity;

-import java.util.ArrayList;
-import java.util.HashSet;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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
Author: badlogic <badlogic@gmail.com>
Date: Mon Aug 26 11:00:07 2013 +0800

fix a

commit 50e1fe0f7df210aec464499eaf6567466ce513e00f
Author: badlogic <badlogic@gmail.com>
Date: Mon Aug 26 11:00:07 2013 +0800

fix b

commit 50e1fe0f7df210aec464499eaf6567466513e21300f
Author: badlogic <badlogic@gmail.com>
Date: Mon Aug 26 11:00:07 2013 +0800

fix c

 git co -b revert_c 50e1fe0f7df210aec464499eaf6567466ce513e00f

git push -u -f origin revert_c:remote_x

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值