为什么在两个日期之间git diff不工作? [英] Why doesn't git diff work between two dates?

查看:363
本文介绍了为什么在两个日期之间git diff不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Eclipse从内部的GitLab服务器检出了一个项目,然后我拉出了所有的变化。当我从Eclipse中查看历史记录。 (Team> show in history),它显示了项目的完整历史。
现在我从终端去相关项目。

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 /

/home/workspace/ProjectX/

我试图通过以下命令获取2个日期之间的差异:

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:


警告:master的日志只能返回到2015年11月10日星期二。

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

如何获取该日期范围内的所有差异?

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

除此之外,Eclipse从远程服务器请求其历史记录。如果我们可以从终端运行相同的命令,那么应该可以运行。

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解析日期如 master @ {2015-10-10} 使用您的反垃圾邮件,这似乎不会回溯到您正在搜索的位置。但是,您可以通过 rev-list 找到该日期范围的提交:

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

您希望文件在该列表中最新和最旧的提交之间进行更改,我们可以使用。我想使用 -n1 - 反向,但 - 反向 -n 之后应用,所以我们不能。

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

设置变量并复制 rev-list 感到笨拙,但是我可以想出的管道版本更糟糕。它选择第一个和最后一个提交,使用 tr 将换行符转换为空格,用 ...替换新空格。使用 sed ,然后将对传递到 git diff

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

这篇关于为什么在两个日期之间git diff不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆