git 查找当前版本和最新版本之间的差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9903541/
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
Finding diff between current and last version
提问by Rajeev
Using Git, how can you find the difference between the current and the last version?
使用 Git,您如何找到当前版本和上一个版本之间的差异?
git diff last version:HEAD
回答by Francisco Puga
I don't really understand the meaning of "last version".
我真的不明白“最后一个版本”的含义。
As the previous commit can be accessed with HEAD^, I think that you are looking for something like:
由于可以使用 HEAD^ 访问先前的提交,因此我认为您正在寻找以下内容:
git diff HEAD^ HEAD
As of Git 1.8.5, @
is an alias for HEAD
, so you can use:
从 Git 1.8.5 开始,@
是 的别名HEAD
,因此您可以使用:
git diff @~..@
The following will also work:
以下也将起作用:
git show
If you want to know the diff between head and any commit you can use:
如果您想知道 head 和任何提交之间的差异,您可以使用:
git diff commit_id HEAD
And this will launch your visual diff tool (if configured):
这将启动您的视觉差异工具(如果已配置):
git difftool HEAD^ HEAD
Since comparison to HEAD is default you can omit it (as pointed out by Orient):
由于与 HEAD 的比较是默认的,您可以省略它(如Orient所指出的):
git diff @^
git diff HEAD^
git diff commit_id
Warnings
警告
- @ScottF and @Panzercrisis explain in the comments that on Windows the
~
character must be used instead of^
.
- @ScottF 和 @Panzercrisis 在评论中解释说在 Windows 上
~
必须使用字符而不是^
.
回答by CharlesB
Assuming "current version" is the working directory (uncommitted modifications) and "last version" is HEAD
(last committed modifications for the current branch), simply do
假设“当前版本”是工作目录(未提交的修改),“上一个版本”是HEAD
(当前分支的最后提交的修改),只需执行
git diff HEAD
Credit for the following goes to user Cerran
.
以下归功于用户Cerran
。
And if you always skip the staging area with -a
when you commit, then you can simply use git diff
.
如果你总是-a
在提交时跳过暂存区,那么你可以简单地使用git diff
.
Summary
概括
git diff
shows unstaged changes.git diff --cached
shows staged changes.git diff HEAD
shows all changes (both staged and unstaged).
git diff
显示未分阶段的更改。git diff --cached
显示阶段性变化。git diff HEAD
显示所有更改(已暂存和未暂存)。
Source: git-diff(1) Manual Page – Cerran
来源:git-diff(1) 手册页 – Cerran
回答by Nighto
回答by Tomilov Anatoliy
Difference between last but one commit and last commit (plus current state, if any):
最后一次提交和最后一次提交之间的区别(加上当前状态,如果有的话):
git diff HEAD~
or even (easier to type)
甚至(更容易打字)
git diff @~
where @
is the synonim for HEAD
of current branch and ~
means "give me the parent of mentioned revision".
当前分支@
的同义词在哪里HEAD
,~
意思是“给我提到修订的父级”。
回答by naoko
You can do it this way too:
你也可以这样做:
Compare with the previous commit
与之前的提交比较
git diff --name-status HEAD~1..HEAD
Compare with the current and previous two commits
与当前和前两次提交进行比较
git diff --name-status HEAD~2..HEAD
回答by Andy
Just use the cached
flag if you added, but haven't committed yet:
cached
如果您添加但尚未提交,请使用该标志:
git diff --cached --color
回答by Bryan
Quick and simple, assuming you're in the master:
快速而简单,假设您在 master 中:
git diff (checkout_id):file.txt file.txt
Example:
例子:
git diff asdfioei91819280din198:file.txt file.txt
回答by parasrish
Firstly, use "git log
" to list the logs for the repository.
首先,使用“ git log
”列出存储库的日志。
Now, select the two commit IDs, pertaining to the two commits. You want to see the differences (example- Top most commit and some older commit (as per your expectation of current-version and some old version)).
现在,选择与两个提交相关的两个提交 ID。您想查看差异(例如- 最重要的提交和一些较旧的提交(根据您对当前版本和一些旧版本的期望))。
Next, use:
接下来,使用:
git diff <commit_id1> <commit_id2>
or
或者
git difftool <commit_id1> <commit_id2>
回答by bit_cracker007
If the top commit is pointed to by HEAD then you can do something like this:
如果 HEAD 指向顶部提交,那么您可以执行以下操作:
commit1 -> HEAD
commit2 -> HEAD~1
commit3 -> HEAD~2
Diff between the first and second commit:
第一次和第二次提交之间的差异:
git diff HEAD~1 HEAD
Diff between first and third commit:
第一次和第三次提交之间的差异:
git diff HEAD~2 HEAD
Diff between second and third commit:
第二次和第三次提交之间的差异:
git diff HEAD~2 HEAD~1
And so on...
等等...
回答by Mandrake
I use Bitbucketwith the EclipseIDE with the Eclipse EGitplugin installed.
我将Bitbucket与EclipseIDE 一起使用,并安装了 Eclipse EGit插件。
I compare a file from any version of its history (like SVN).
我比较来自其历史记录的任何版本的文件(如SVN)。
Menu Project Explorer → File→ right click → Team→ Show in history.
菜单项目资源管理器 →文件→ 右键单击 →团队→在历史中显示。
This will bring the history of all changes on that file. Now Ctrlclick and select any two versions→ "Compare with each other".
这将带来该文件上所有更改的历史记录。现在Ctrl单击并选择任意两个版本→ “相互比较”。