git diff 用法

参考链接: http://xahlee.info/linux/git_diff.html

本文阐述 git diff 的不同用法。

git 中有三个主要区域

  • Working Directory 工作区。当前用户正在工作的区域
  • Staging Area(也被叫做 cache,index)。使用 git add 后存放的临时位置
  • HEAD 指向一个 commit 位置。通常情况下,是指上一次提交

上面的三个区域,都是在你本地的。每个 commit 都会有一个特定的标识(id),我们称之为 commit id。

如何查看 commit

# 显示最近的三次 commit
git log -3

diff between {working dir, staging area}

# diff working dir, staging area
git diff --color

# diff working dir, staging area, 1 file
git diff --color filename

diff between {staging area, last commit}

# diff satging area, last commit. 其中 staged 参数也可用 cached 替代
git diff --color --staged <commitID>

diff between {last commit, working dir}

git diff --color <commitID>

对同一分支的两个 commit 进行 diff

  1. git log file_name
  2. git diff commit_ID_1 commit_ID_2 file_name

查看哪些文件被 staged 了

# 获取当前的状态
git status .

# 推荐使用下面的,简洁明了
git status -s
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值