git 如何区分本地未提交的更改和原点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17688594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Diff between local uncommitted changes and origin
提问by Chaitanya
Let's say I cloned a repository and started modifying files. I know that if I have local uncommitted changes, I can do a diff as follows git diff test.txt
and it will show me the difference between the current local HEAD and the modified, uncommitted changes in the file. If I commit those changes I can diff it against the original repository by using git diff master origin/master
假设我克隆了一个存储库并开始修改文件。我知道如果我有本地未提交的更改,我可以按如下方式进行比较,git diff test.txt
它将显示当前本地 HEAD 与文件中修改后的未提交更改之间的差异。如果我提交这些更改,我可以通过使用将其与原始存储库进行比较git diff master origin/master
But is there any way of diff'ing the local changes with the original repository on the server beforecommitting locally? I tried various permutations of git diff --cached master origin/master
with no luck.
但是,在本地提交之前,是否有任何方法可以将本地更改与服务器上的原始存储库进行比较?我尝试了各种排列,但git diff --cached master origin/master
没有运气。
采纳答案by JJD
Given that the remote repository has been cached via git fetch
it should be possible to compare against these commits. Try the following:
鉴于远程存储库已通过缓存git fetch
,应该可以与这些提交进行比较。请尝试以下操作:
$ git fetch origin
$ git diff origin/master
回答by Nate
I know it's not an answer to the exact question asked, but I found this question looking to diff a filein a branch and a local uncommitted file and I figured I would share
我知道这不是一个问题的确切问题问过,但我发现这个问题寻找一个差异文件中的一个分支和本地未提交的文件,我想我会分享
Syntax:
句法:
git diff <commit-ish>:./ -- <path>
Examples:
例子:
git diff origin/master:./ -- README.md
git diff HEAD^:./ -- README.md
git diff stash@{0}:./ -- README.md
git diff 1A2B3C4D:./ -- README.md
(Thanks Eric Boehs for a way to not have to type the filename twice)
(感谢 Eric Boehs 提供了一种不必两次输入文件名的方法)
回答by pepestar
To see non-staged (non-added) changes to existing files
查看对现有文件的非暂存(非添加)更改
git diff
git diff
Note that this does not track new files. To see staged, non-commited changes
请注意,这不会跟踪新文件。查看暂存的、未提交的更改
git diff --cached
git diff --cached
回答by Caner
If you want to compare files visually you can use:
如果要直观地比较文件,可以使用:
git difftool
It will start your diff app automatically for each changed file.
它将为每个更改的文件自动启动您的差异应用程序。
PS: If you did not set a diff app, you can do it like in the example below(I use Winmerge):
PS:如果你没有设置差异应用程序,你可以像下面的例子中那样做(我使用Winmerge):
git config --global merge.tool winmerge
git config --replace --global mergetool.winmerge.cmd "\"C:\Program Files (x86)\WinMerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\""
git config --global mergetool.prompt false