我foo在master分支中有一个repo文件.我切换到酒吧分支并进行了一些更改foo.我现在如何git diff在此副本(尚未提交)和主分支副本之间运行?
Mar*_*air 127
以下适用于我:
git diff master:foo foo
在过去,它可能是:
git diff foo master:foo
Jor*_*ugh 97
您正在尝试将工作树与特定分支名称进行比较,因此您需要:
git diff master -- foo
Run Code Online (Sandbox Code Playgroud)
这是从这种形式的git-diff(参见git-diff手册页)
git diff [--options] <commit> [--] [<path>...]
This form is to view the changes you have in your working tree
relative to the named <commit>. You can use HEAD to compare it with
the latest commit, or a branch name to compare with the tip of a
different branch.
Run Code Online (Sandbox Code Playgroud)
仅供参考,还有一个--cached(aka --staged)选项可用于查看您上演的内容的差异,而不是工作树中的所有内容:
git diff [--options] --cached [<commit>] [--] [<path>...]
This form is to view the changes you staged for the next commit
relative to the named <commit>.
...
--staged is a synonym of --cached.
Run Code Online (Sandbox Code Playgroud)
git diff mybranch master -- file
Run Code Online (Sandbox Code Playgroud)
也应该工作
查看与当前分支相比的本地更改
git diff .
Run Code Online (Sandbox Code Playgroud)
与任何其他现有分支相比,查看本地更改
git diff <branch-name> .
Run Code Online (Sandbox Code Playgroud)
查看特定文件的更改
git diff <branch-name> -- <file-path>
Run Code Online (Sandbox Code Playgroud)
确保git fetch一开始就跑。