从“git diff”中排除单个提交 [英] Exclude a single commit from a "git diff"
问题描述
早上所有,
假设我有一系列提交,如下所示:
我知道我可以使用
$ git diff -c --binary abc000..def555> /tmp/abc000_def555.patch
生成一个补丁程序,将系统从abc000升级到def555。 p>
但是如果我想(因为无法进入)从补丁中排除def333,我该怎么做?请注意,我不想恢复def333,它只是我不希望该补丁包含此提交。
谢谢
其实 all git diff
s是commit-pair-wise: abc000
中的树/文件与 def555
中的树/文件。如果例如 def333
改变 dir / file
但是没有改变 dir / file
之间 abc000
和 def555
(例如, def333
被某些事情取消了)你可能根本看不到 dir / file
。
一般情况下,在 def333
中进行的更改将以某种方式更改 dir / file
将 abc000
中的版本与 def555
中的版本进行比较时显示出来。所以你会可能看到这种变化。
获取diff的最简单方法是显示what def555 code>会看起来像是
def333
被还原了就是这样做的:创建一个树(在一个临时分支上)并且更改被还原。要使用实际的命名分支,你可以这样做:
git checkout def555#by ID,让你得到一个分离的HEAD
git checkout -b temp-branch
git revert --no-edit def333
git diff [options] abc000
git checkout somebranch; git分支-D临时分支
如果您不想要临时分支,该怎么办?那么,这是微不足道的:只是不要创建一个。像上面那样得到一个分离的HEAD,按照上面的方法进行还原,然后执行 git checkout somebranch
。没有临时分支可以删除,除了那个未命名的分支,git会警告你将要离开......这正是你想要的。
Morning all, Let's say I have a series of commits as follows:
- abc000
- def111
- abc222
- def333
- abc444
- def555
I know I can use
$ git diff -c --binary abc000..def555 > /tmp/abc000_def555.patch
to produce a patch to upgrade a system from abc000 to def555.
But what if I wanted to (for reasons to dull to get into) exclude def333 from the patch - how can I do this? Note that I do not want to revert def333, its just that I do not want the patch to incorporate this commit.
Thanks
Actually all git diff
s are commit-pair-wise: the above compares the trees/files in abc000
against those in def555
. If for instance def333
changes dir/file
but there are no changes to dir/file
between abc000
and def555
(e.g., the change in def333
is canceled out by something along the way) you might not see dir/file
in there at all.
In general, though, changes made in def333
will have altered dir/file
in a way that shows up when comparing the version in abc000
against the one in def555
. So you will probably see that change.
The easiest way to get a diff that shows "what def555
would look like if def333
were reverted" is to do just that: create a tree (on a temporary branch) with the change reverted. To do it with an actual named branch, you might do something like this:
git checkout def555 # by ID, so that you get a "detached HEAD"
git checkout -b temp-branch
git revert --no-edit def333
git diff [options] abc000
git checkout somebranch; git branch -D temp-branch
What if you don't want a temp branch? Well, that's trivial: just don't create one. Get a "detached HEAD" as above, do the revert as above, and then git checkout somebranch
. There's no temporary branch to delete, except for the unnamed one that git will warn that you are leaving behind ... which is just what you wanted.
这篇关于从“git diff”中排除单个提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!