如何查看上次提交和现在之间发生了什么变化(进行了一些更改后) [英] How to see whats changed between last commit and now(after making some changes)

查看:184
本文介绍了如何查看上次提交和现在之间发生了什么变化(进行了一些更改后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于此问题但是我怎么看到我上次提交和当前状态之间有什么变化,这会有一些变化。

因此,根据链接问题,是这样的



在两个不同的SHA之间:

  git diff --name-only SHA1 SHA2 

查看第十次最新提交和第五次最新提交):

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $


$ b $ p $现在我在当前状态和上次提交之间进行尝试:

  git diff HEAD HEAD〜1 

注意 I将会留下 - 仅限名称,因为我有兴趣查看文件中发生了什么变化。

解决方案


... current state =做了一个提交,在一个文件中改了一些东西,并没有做一个git add。


OK ,在这种情况下,您想比较工作树文件和已经提交的文件。 已经提交的东西是 HEAD (当前提交)或 HEAD ^ 1 aka HEAD〜1 ,即当前提交的第一个父项。



虽然有很多 git diff 变体( git diff-index git diff-files git diff -tree ),最基本也最简单的是 git diff 本身,这就是你需要的。



默认情况下, git diff< commit-specifier> 将指定的提交与当前工作树进行比较。所以如果你想看看你还没有 git add -ed:

  git diff HEAD 

这会给你一个正常的每日差异来展示如何改变 HEAD 的内容复制到当前在工作树中的内容中。 (你可以添加 - 仅限名称 - 名称状态以获取文件名,或文件名和状态码,但你说你想要完整的差异。)



要了解如何从 HEAD〜 1 到当前工作树,使用 git diff HEAD〜1


将会很好地知道如何引用它们...


基本的 git diff 命令实际上可以完成其中的大部分功能(其中一些功能是Git版本1.6和1.7中新增加的,但人们在实践中使用的最古老的Git版本似乎是1.7.1左右,这些应该是可用的):


  • git diff< commit> ; :比较< commit>到工作树。当< commit>是字面上的单词 HEAD 您最终将当前提交(不是索引)与工作树进行比较。


  • git diff (没有额外的标志参数):比较当前的索引与工作树。这与第一个类似,但不一样。特别是,一旦你 git add 文件,你在索引中更新版本,所以现在索引版本将匹配工作树版本,因此你不会看到它在 git diff 输出中,即使它实际上还没有被提交

    (当然,您可以安全地添加一些标志参数,如 - 仅限名称。关键是您不能添加 - 暂存 - 缓存在这里。)


  • git diff --staged (也可以拼写为 git diff --cached ):compare HEAD (当前提交)与索引。也就是说,在前面的(无标志) git diff 中看到的任何内容,都可以将 git add 添加到索引更新索引;那么你不会在 git diff 中看到它,但是你会在 git diff --staged


  • git diff< commit1> < commit2> :比较两个提交。例如, git diff HEAD〜1 HEAD 将一步后退提交( HEAD〜1 )与当前提交( HEAD )。




选择;请参阅 git diff $ b $( HEAD ^ number HEAD〜 number ,但仅当 number 部分不是1.代字符后缀语法会移回一些第一父母,而hat-suffix语法则会选择第二个父代,这实际上只代表任何合并提交。您可以省略号码并重复帽子后缀,例如, HEAD ^^^^ ,这意味着与 HEAD〜4 。当你刚刚返回时,使用你认为更容易输入的内容:该数字默认为1)。


similar to this question but how do I see what has changed between my last commit and my current state, which would have some changes.

So based on the linked question, it would be something like this

between 2 different SHAs:

git diff --name-only SHA1 SHA2

to see the differences between the tenth latest commit and the fifth latest (or so):

git diff --name-only HEAD~10 HEAD~5

Now my attempt between the current state and the last commit:

git diff HEAD HEAD~1

Note I would leave --name-only out as I am interested in seeing what was changed in the file.

解决方案

... current state = did a commit, changed something in a file and did not do a git add.

OK, in this case you want to compare the work-tree files, against something already committed. The "something already committed" is either HEAD (the current commit) or HEAD^1 aka HEAD~1, the current commit's first-parent.

While there are many git diff variants (git diff-index, git diff-files, and git diff-tree), the most basic and simple one is git diff itself, and that's the one you need here.

By default, git diff <commit-specifier> compares the specified commit to the current work-tree. So if you want to see what you have not yet git add-ed:

git diff HEAD

This gives you a normal, every-day diff that shows how to change "contents of HEAD" into "contents currently in work-tree". (You could add --name-only or --name-status to get file names only, or file names and status codes, but you said you wanted the full diffs.)

To see how to change from HEAD~1 to the current work-tree, use git diff HEAD~1.

would be good to know how to refer to them all ...

The basic git diff command can in fact do most of them (some of these capabilities were newly added in Git versions 1.6 and 1.7, but the most ancient version of Git that people use in practice today seems to be 1.7.1 or so, by which these should be available):

  • git diff <commit>: compare <commit> to the work-tree. When <commit> is the literal word HEAD you end up comparing the current commit (not the index) vs the work-tree.

  • git diff (with no extra flag arguments): compare the current index vs the work-tree. This is similar to the first, but not the same. In particular, once you git add a file, you update the version in the index, so now the index version will match the work-tree version and hence you won't see it in git diff output, even if it's not actually committed yet.

    (Of course, you can safely add some flag arguments, like --name-only. The key is that you can't add --staged or --cached here.)

  • git diff --staged (can also be spelled git diff --cached): compare HEAD (the current commit) vs the index. That is, anything you see in the previous (no-flags) git diff, you can git add to the index to update the index; then you won't see it in git diff but you will see it in git diff --staged.

  • git diff <commit1> <commit2>: compare the two commits. For instance, git diff HEAD~1 HEAD compares the one-step-back commit (HEAD~1) to the current commit (HEAD).

There are still more options; see the git diff documentation for a more complete list.

(There is a significant difference between HEAD^number and HEAD~number, but only when the number part is not 1. The tilde-suffix syntax moves back some number of first parents while the hat-suffix syntax selects the n'th parent, which really only means anything for merge commits. You can omit the number and repeat the hat suffix, e.g., HEAD^^^^, and it means the same thing as HEAD~4. When you're just going back one, use whichever you find easier to type: the number defaults to 1.)

这篇关于如何查看上次提交和现在之间发生了什么变化(进行了一些更改后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆