Git diff 与藏匿处
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7677736/
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
Git diff against a stash
提问by James
How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them!
我如何才能看到 un-stashing 对当前工作树所做的更改?我想知道在应用它们之前会进行哪些更改!
回答by Amber
See the most recent stash:
查看最近的存储:
git stash show -p
See an arbitrary stash:
查看任意存储:
git stash show -p stash@{1}
From the git stash
manpages:
从git stash
联机帮助页:
By default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form).
默认情况下,该命令显示 diffstat,但它会接受 git diff 已知的任何格式(例如, git stash show -p stash@{1} 以补丁形式查看第二个最近的存储)。
回答by czerasz
To see the most recent stash:
要查看最近的存储:
git stash show -p
To see an arbitrary stash:
要查看任意存储:
git stash show -p stash@{1}
Also, I use git diff to compare the stash with any branch.
另外,我使用 git diff 将存储与任何分支进行比较。
You can use:
您可以使用:
git diff stash@{0} master
To see all changes compared to branch master.
Or You can use:
查看与分支 master 相比的所有更改。
或者您可以使用:
git diff --name-only stash@{0} master
To easy find only changed file names.
轻松查找仅更改的文件名。
回答by t.heintz
If the branch that your stashed changes are based on has changed in the meantime, this command may be useful:
如果您的隐藏更改所基于的分支在此期间发生了更改,则此命令可能很有用:
git diff stash@{0}^!
This compares the stash against the commit it is based on.
这将存储与其所基于的提交进行比较。
回答by Magne
If your working tree is dirty, you can compare it to a stash by first committing the dirty working tree, and then comparing it to the stash. Afterwards, you may undo the commit with the dirty working tree (since you might not want to have that dirty commit in your commit log).
如果您的工作树是脏的,您可以通过首先提交脏工作树,然后将其与存储进行比较,将其与存储进行比较。之后,您可以使用脏工作树撤消提交(因为您可能不希望在提交日志中包含该脏提交)。
You can also use the following approach to compare two stashes with each other (in which case you just pop one of the stashes at first).
您还可以使用以下方法将两个 stashes 相互比较(在这种情况下,您只需先弹出其中一个 stashes)。
Commit your dirty working tree:
git add . git commit -m "Dirty commit"
Diff the stash with that commit:
git diff HEAD stash@{0}
Then, afterwards, you may revert the commit, and put it back in the working dir:
git reset --soft HEAD~1 git reset .
提交你肮脏的工作树:
git add . git commit -m "Dirty commit"
使用该提交区分存储:
git diff HEAD stash@{0}
然后,之后,您可以恢复提交,并将其放回工作目录:
git reset --soft HEAD~1 git reset .
Now you've diffed the dirty working tree with your stash, and are back to where you were initially.
现在你已经用你的藏品区分了肮脏的工作树,并回到了你最初的地方。
回答by SensorSmith
@Magne's answeris the only one to (very late) date that answers the most flexible/useful interpretation of the question, but its a fair bit more complicated than necessary. Rather than committing and resetting, just stash your working copy, compare, then unstash.
@Magne 的答案是迄今为止(很晚)唯一一个回答问题的最灵活/最有用的解释的答案,但它比必要的要复杂一些。而不是提交和重置,只需存储您的工作副本,比较,然后取消存储。
git stash save "temp"
git diff stash@{0} stash@{1}
git stash pop
That shows you the differences between the top of the stash stack and your working folder by temporarily making your working folder changes become the top of the stash stack (stash@{0}), moving the original top down one (stash@{1}) then comparing using the original top in the 'new set' position so you see the changes that would result from applying it on top of your current work.
通过临时使您的工作文件夹更改成为存储堆栈顶部 (stash@{0}),将原始顶部向下移动 (stash@{1} ) 然后在“新设置”位置使用原始顶部进行比较,这样您就可以看到将其应用于当前工作的顶部所产生的变化。
"But what if I don't have any current work?"Then you are in the normal boring case. Just use @Amber's answer
“但如果我目前没有任何工作呢?” 那么你就处于正常无聊的情况。只需使用@Amber的答案
git stash show
or @czerasz's answer
或@czerasz 的回答
git diff stash@{0}
or admit that stashing and unstashing is fast and easy anyway, just unstash the changes and inspect them. If you don't want them at the moment throw them (the current index/working folder changes) away. In full that's
或者承认 stash 和 unstashing 是快速和容易的,只需 unstash 更改并检查它们。如果您现在不想要它们,请将它们(当前索引/工作文件夹更改)扔掉。完整的就是
git stash apply
git diff
git reset
git checkout
回答by Rimian
This works for me on git version 1.8.5.2:
这在 git 版本 1.8.5.2 上对我有用:
git diff stash HEAD
回答by Pramod B R
Just in case, to compare a file in the working tree and in the stash, use the below command
以防万一,要比较工作树和存储中的文件,请使用以下命令
git diff stash@{0} -- fileName (with path)
回答by yerlilbilgin
If you have tools for diff (like beyond compare)
如果您有差异工具(例如无与伦比的)
git difftool stash HEAD
回答by xenithorb
One way to do this without moving anything is to take advantage of the fact that patch
can read git diff's (unified diffs basically)
在不移动任何东西的情况下做到这一点的一种方法是利用patch
可以读取 git diff 的事实(基本上是统一的差异)
git stash show -p | patch -p1 --verbose --dry-run
This will show you a step-by-step preview of what patch would ordinarily do. The added benefit to this is that patch won't prevent itself from writing the patch to the working tree either, if for some reason you just really need git to shut up about commiting-before-modifying, go ahead and remove --dry-run and follow the verbose instructions.
这将向您展示补丁通常会做什么的分步预览。这样做的额外好处是补丁也不会阻止自己将补丁写入工作树,如果由于某种原因你真的需要 git 关闭提交前修改,继续并删除 --dry-运行并按照详细说明进行操作。
回答by Ferrard
Combining what I learned in this thread and in this one, when I want to see "what is inside the stash", I first run:
结合我在这个线程和了解到这个,当我想看看“什么是里面藏”,我第一次运行:
git stash show stash@{0}
That will show what files were modified. Then, to get a nice visual diff in a difftool, I do:
这将显示哪些文件被修改。然后,为了在 difftool 中获得不错的视觉差异,我执行以下操作:
git difftool --dir-diff stash@{0} stash@{0}^
This will display all the differences at once of the given stash against its parent.
这将立即显示给定存储与其父存储的所有差异。
You can configure the diff tool in ~/.gitconfig
, e.g. with Meld:
您可以在 中配置差异工具~/.gitconfig
,例如使用Meld:
...
[diff]
tool = meld