[英]Finding diff between current and last version
使用 Git,您如何找到当前版本和上一个版本之间的差异?
git diff last version:HEAD
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
~
character must be used instead of ^
. @ScottF 和 @Panzercrisis 在评论中解释说,在 Windows 上必须使用~
字符而不是^
。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
用户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
显示未暂存的更改。git diff --cached
shows staged changes. git diff --cached
显示阶段性更改。git diff HEAD
shows all changes (both staged and unstaged). git diff HEAD
显示所有更改(已暂存和未暂存)。Source: git-diff(1) Manual Page – Cerran来源:git-diff(1) 手册页 – Cerran
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
的同义词, ~
表示“给我提到的修订版的父级”。
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
如果您添加但尚未提交,只需使用cached
标志:
git diff --cached --color
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
Firstly, use " git log
" to list the logs for the repository.首先,使用“ git log
”列出存储库的日志。
Now, select the two commit IDs, pertaining to the two commits.现在,选择与两个提交相关的两个提交 ID。 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) ).您想查看差异(例如- 最重要的提交和一些较旧的提交(根据您对当前版本和一些旧版本的期望) )。
Next, use:接下来,使用:
git diff <commit_id1> <commit_id2>
or要么
git difftool <commit_id1> <commit_id2>
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...等等...
If you want the changes for the last n
commits, you can use the following:如果您想要最后n
提交的更改,您可以使用以下命令:
git diff HEAD~n
So for the last 5 commits (count including your current commit) from the current commit, it would be:因此,对于当前提交的最后 5 次提交(包括您当前的提交计数),它将是:
git diff HEAD~5
I use Bitbucket with the Eclipse IDE with the Eclipse EGit plugin installed.我将Bitbucket与Eclipse IDE 一起使用,并安装了 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 Ctrl click and select any two versions→ "Compare with each other" .现在Ctrl单击并选择任意两个版本→ “相互比较” 。
This will also work for tags (remove the 'uniq' below and other parts if you need to see all changes):这也适用于标签(如果您需要查看所有更改,请删除下面的“uniq”和其他部分):
git diff v1.58 HEAD
The below is the same, and that could be useful for continuous integration (CI) for microservices in a monolithic repository:下面是相同的,这对于单体存储库中微服务的持续集成(CI) 可能很有用:
git diff v1.58 HEAD --name-only | sort -u | awk 'BEGIN {FS="/"} {print $1}' | uniq
<Folder Name>
(Credit - https://dzone.com/articles/build-test-and-deploy-apps-independently-from-a-mo ) (信用 - https://dzone.com/articles/build-test-and-deploy-apps-independently-from-a-mo )
to show individual changes in a commit, to head.显示提交中的单个更改,以头部。
git show Head~0
to show accumulated changes in a commit, to head.显示提交中累积的更改,到头。
git diff Head~0
where 0 is the desired number of commits.其中 0 是所需的提交次数。
If last versions means last tag , and current versions means HEAD (current state), it's just a diff with the last tag:如果 last versions 表示last tag ,而当前版本表示 HEAD (当前状态),则它只是与 last tag 的差异:
$ git tag --list
...
v20.11.23.4
v20.11.25.1
v20.11.25.2
v20.11.25.351
The last tag would be:最后一个标签是:
$ git tag --list | tail -n 1
v20.11.25.351
Putting it together:把它放在一起:
tag=$(git tag --list | tail -n 1)
git diff $tag
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.