我在不同的分支中有两个不同的文件.如何在一个命令中区分它们?
就像是
# git diff branch1/foo.txt branch2/foo-another.txt
Run Code Online (Sandbox Code Playgroud)
我可以看看另一个文件,差异并恢复,但这是非常脏的解决方案.
twa*_*ggs 208
git diff branch1:full/path/to/foo.txt branch2:full/path/to/foo-another.txt
Run Code Online (Sandbox Code Playgroud)
您还可以使用相对路径:
git diff branch1:./relative/path/to/foo.txt branch2:./relative/path/to/foo-another.txt
Run Code Online (Sandbox Code Playgroud)
Cam*_*mpa 21
旁注:不需要完整路径,您可以从./相对路径开始.它有时候很方便.
git diff branch1:./relative/path/to/foo.txt branch2:./relative/path/to/foo-another.txt
Run Code Online (Sandbox Code Playgroud)
Rom*_*eri 12
题外话答案——在不同分支中比较同一文件
只是为了添加它,我发现它是一个非常简单的语法:
git diff <branch1> <branch2> <filepath>
Run Code Online (Sandbox Code Playgroud)
也适用于相对引用,例如:
# compare the previous committed state from HEAD with the state branch1 was 3 commits ago
git diff HEAD^ <branch1>~3 <filepath>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37855 次 |
| 最近记录: |