SourceTree:如何在相反的方向上做一个git diff?

时间:2013-07-26 00:34:54

标签: git git-diff atlassian-sourcetree

如何在Atlassian SourceTree中向相反方向执行git diff?换句话说,如何让SourceTree执行git diff b a而不是git diff a b

例如,如果我的提交在我的提交窗格中按此顺序排列:

  3333
  2222
  1111

我选择3333和1111,它会显示从1111到3333的变化差异(即git diff 1111 3333)。

如何让它在另一个方向上进行git diff,以便它从3333变为1111(即git diff 3333 1111)?

Here is a screenshot showing where I selected 2 commits in SourceTree to see the diff

4 个答案:

答案 0 :(得分:2)

这在SourceTree中是不可能的。

我问了这个问题here on answers.atlassian.com并且从Atlassian员工那里发现,在相反方向上做差异的能力是不可用的,提交之间的差异总是显示在"前进历史&# 34;顺序。

一些替代方案:

  1. 使用其他外部GUI差异查看器


    -OR -

  2. 将较早提交1111中的文件复制到较新提交3333的工作树中,然后查看工作树中的差异,例如,
  3. $ cd {repo}
    $ git diff --name-only 3333..1111 > /tmp/list_of_files_changed
    $ git checkout 1111
    $ mkdir /tmp/files_changed
    $ cp --parents -pr $(cat /tmp/list_of_files_changed) /tmp/files_changed 
    $ git checkout 3333
    $ cp -pr /tmp/files_changed/* .
    # (now look at the diff in SourceTree for the working copy)
    

答案 1 :(得分:2)

假设您需要从当前分支中区分出一个特定的分支,唯一的方法是Berik答案,因为不可能将分支通知为第二个参数。

所以这显示diff正常顺序:

git diff branch_abc Makefile

并以相反的顺序显示差异:

git diff -R branch_abc Makefile

答案 2 :(得分:-1)

可以通过切换提交顺序来实现:

$ git diff HEAD 21da2e
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
 import java.net.SocketException;
-import java.net.URL;
+import java.net.URI;
$ git diff 21da2e HEAD

+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
 import java.net.SocketException;
-import java.net.URI;
+import java.net.URL;

答案 3 :(得分:-2)

编写

会很好
# will display the additions as + and subtractions as -
git diff first second

# will display the additions as - (in red) and subtractions as + (in green)
git diff second first

这在标准git中应该可以正常工作。