Git diff,但仅适用于另一个分支上的更改 [英] Git diff but only for changes on another branch

查看:69
本文介绍了Git diff,但仅适用于另一个分支上的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在git中有一个branch0.

Suppose I have a branch0 in git.

从这个branch0我创建一个branch1并开始对其进行操作.一段时间后,我将更改提交到该分支1.同时branch0正在更改.

From this branch0 I create a branch1 and start working on it. After a while I committed changes to this branch1. Meanwhile branch0 is being changed.

如果将branch1的最新版本与branch0进行比较,我将看到分支之间的所有更改,而不仅是与branch1中的更改​​相关的更改.

If I compare the latest version of branch1 against branch0 I will see all the changes between the branches, not only the changes that correlate to the changes in branch1.

例如,如果在branch0中修改了文件,但在branch1上未修改文件,则git diff将向我显示对该文件的更改.但是,该文件未在branch1上修改.因此,我希望在差异中将其忽略.

For example, if a file was modified in the branch0, but the file was not modified on branch1, the git diff will show me the changes to the file. However the file was not modified on branch1. So I would like it to be ignored in the diff.

从某种意义上说,我想在branch1和branch0之间做一个git diff,但只对在branch1中修改过的文件做.

In a sense, I'd like to do a git diff between branch1 and branch0, but only for the files that were modified in branch1.

在git中可以吗?我可以想象用bash进行操作,列出所有文件,然后逐个进行比较.但是想知道git中是否有更简单的方法.

Is it possible in git? I can imagine doing it in bash, listing all the files and doing a diff on a one-by-one. But wanted to know if there's an easier way in git.

推荐答案

您可以为此使用比较任意提交

You can use compare arbitrary commits for that

与任意提交比较

Comparing with arbitrary commits

$ git diff test            <1>
$ git diff HEAD -- ./test  <2>
$ git diff HEAD^ HEAD      <3>

  1. 与使用"test"分支的尖端进行比较,而不是使用当前分支的尖端.

  1. Instead of using the tip of the current branch, compare with the tip of "test" branch.

与其与"test"分支的尖端进行比较,而不是与当前分支的尖端进行比较,但将比较限制在文件"test"中.

Instead of comparing with the tip of "test" branch, compare with the tip of the current branch, but limit the comparison to the file "test".

比较上一次提交和最后一次提交之前的版本.

Compare the version before the last commit and the last commit.

来自 =示例" ,位于 http://git-scm.com/docs/git-diff .

假设您有这个git树

1---2 (branch0)
     \
      3 (branch 1)

在提交3中,您对branch1进行了更改,现在我们应用并将某些更改提交到branch0

where in commit 3 you have the changes made to branch1, now we apply and commit some changes to branch0

1---2---4 (branch0)
     \
      3 (branch 1)

如果您现在这样做

$ git checkout branch1
$ git diff branch0

它将显示这些分支之间的所有更改,包括您已经说过的在提交4中应用的更改. 但是您只想查看branch1的更改,它基本上是与分支分支的提交的差异,因此这应该可以完成

it will show all the changes between these branches, including the changes that were applied in commit 4 like you already stated. But you only want to view the changes of branch1, which is basically a diff against the commit that it was branched off of, so this should do the job

$ git checkout branch1
$ git diff 2

其中2只是提交哈希的一个示例,实际上看起来更像e542ghe或类似的东西

where 2 is just an example of a commit hash and would actually look more like e542ghe or something similar

这篇关于Git diff,但仅适用于另一个分支上的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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