diff git 指定时间_为什么在两个日期之间git diff不工作?

I checked out a project from an internal GitLab server using Eclipse, then I pulled all the changes. When I view the history from Eclipse. (Team > show in history), it displays the full history of the project.

Now I go to the relevant project from the terminal.

/home/workspace/ProjectX/

I am trying to get the differences between 2 dates with the following command:

git diff --name-only master@{2015-10-10}..master@{2015-11-10} > /home/results/ProjectX/Changes.txt

It wont display any result for that. It displays:

warning: Log for 'master' only goes back to Tue, 10 Nov 2015.

How can I get all the differences in that date range?

In addition to that, how does Eclipse request its history from the remote server. If we can run the same command from the terminal, that should work.

解决方案

Git parses dates like master@{2015-10-10} using your reflog, which doesn't appear to go back as far as you're searching. But, you can find commits for that date range anyway with rev-list:

git rev-list --since='2015-10-10' --until='2015-11-10' master

You want the files changes between the most recent and the oldest commit in that list, which we can get using head and tail. I'd like to use -n1 and --reverse, but --reverse applies after -n, so we can't.

first=$(git rev-list --since='2015-10-10' --until='2015-11-10' master | tail -1)

last=$(git rev-list --since='2015-10-10' --until='2015-11-10' master | head -1)

git diff --name-only $first..$last

Setting variables and duplicating the rev-list feels clumsy, but the pipe-y version I can come up with is sort of worse. It picks the first and last commits, converts the newline to a space using tr, replaces the new space with .. using sed, then passes the pair off to git diff.

git rev-list --since='2015-10-10' --until='2015-11-10' master | \

(head -n1 && tail -n1) | \

tr '\n' ' ' | \

sed 's/ /../' | \

xargs git diff --name-only

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值