修复合并冲突后,我希望在添加未合并文件以解决冲突之前查看未合并文件的实际差异。
我可以看到每个文件的差异与git diff HEAD,但这也显示了不同的非冲突的文件。
我可以看到未合并的文件与git diff,但这显示了冲突,而不是实际的差异。
如何才能看到HEAD与实际文件内容之间的差异,只针对冲突的文件?
下面是如何创建一个repro (在一个空目录中):
git init
# Create files foo.txt and bar.txt on master.
git commit --allow-empty -m "Initial commit"
echo 'foo content' > foo.txt
echo 'bar content' > bar.txt
git add .
git commit -m A
# Create a branch "b" that change both files.
git checkout -b b
echo 'Foo content' > foo.txt
echo 'Bar content' > bar.txt
git add .
git commit -m B
# Get back on master and add a commit that change foo.txt.
git checkout -
echo 'foo content and more' > foo.txt
git add foo.txt
git commit -m C
# Try to merge b in master: CONFLICT!
git merge b
# Fix the conflict.
echo 'Foo content and more' > foo.txt现在,git diff HEAD给出了所有更改的列表,包括不冲突的bar.txt:
diff --git a/bar.txt b/bar.txt
index 085e7f5..6401b08 100644
--- a/bar.txt
+++ b/bar.txt
@@ -1 +1 @@
-bar content
+Bar content
diff --git a/foo.txt b/foo.txt
index 6633fd8..a65c68b 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo content and more
+Foo content and more另一方面,git diff只给出冲突的文件,但它没有显示磁盘上的实际内容与HEAD之间的实际差异。
diff --cc foo.txt
index 6633fd8,6fc4556..0000000
--- a/foo.txt
+++ b/foo.txt
@@@ -1,1 -1,1 +1,1 @@@
- foo content and more
-Foo content
++Foo content and more我希望命令具有与git diff HEAD -- foo.txt相同的输出,但不需要指定冲突的文件。
git diff --magic-flag HEAD
diff --git a/foo.txt b/foo.txt
index 6633fd8..a65c68b 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo content and more
+Foo content and more发布于 2019-03-06 09:03:12
此命令似乎完成了以下任务:
git diff HEAD -- $(git diff --name-only --diff-filter=U)我将其命名为git dhu (diff head u),在~/.gitconfig中。
[alias]
dhu = !git diff HEAD -- $(git diff --name-only --diff-filter=U)https://stackoverflow.com/questions/55003413
复制相似问题