是否可以在 git 中预览存储内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3573623/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:57:18  来源:igfitidea点击:

Is it possible to preview stash contents in git?

gitgit-stash

提问by Benjol

I often put work away for later, then other stuff comes along, and a few weeks later, I want to inspect the stash, and find out what changes it would make if I applied it to working tree in its current state.

我经常把工作留到以后,然后其他东西又出现了,几周后,我想检查存储,并找出如果我将它应用于当前状态的工作树会产生什么变化。

I know I can do a git diff on the stash, but this shows me all the differences between the working tree and the stash, whereas I'm just interested to know what the stash apply is going to change.

我知道我可以在 stash 上做一个 git diff,但这向我展示了工作树和 stash 之间的所有差异,而我只是想知道 stash apply 将改变什么。

How can I do this?

我怎样才能做到这一点?

回答by Jlew

git stash showwill show you the files that changed in your most recent stash. You can add the -poption to show the diff.

git stash show将向您显示最近存储中更改的文件。您可以添加-p选项以显示差异。

git stash show -p

If the stash you are interested in is not the most recent one, then add the name of the stash to the end of the command:

如果您感兴趣的 stash 不是最新的,则将 stash 的名称添加到命令的末尾:

git stash show -p stash@{2}

回答by segfault

To view a current list of stash:

要查看当前的存储列表:

git stash list

You'll see a list like this:

你会看到一个这样的列表:

stash@{0}: WIP on ...
stash@{1}: ...
stash@{2}: ...
...

To view diff on any of those stashes:

要查看任何这些存储的差异:

git stash show -p stash@{n}

回答by Jeff Ward

I'm a fan of gitk's graphical UI to visualize git repos. You can view the last item stashed with:

我是gitk可视化 git repos 的图形 UI的粉丝。您可以查看存储的最后一个项目:

gitk stash

You can also use view any of your stashed changes (as listed by git stash list). For example:

您还可以使用查看任何隐藏的更改(由 列出git stash list)。例如:

gitk stash@{2}

In the below screenshot, you can see the stash as a commit in the upper-left, when and where it came from in commit history, the list of files modified on the bottom right, and the line-by-line diff in the lower-left. All while the stash is still tucked away.

在下面的屏幕截图中,您可以在左上角看到 stash 作为提交,在提交历史记录中它来自何时何地,右下角是修改的文件列表,以及下角的逐行差异-剩下。一直以来,藏匿处都被藏起来了。

gitk viewing a stash

gitk 查看藏匿处

回答by Wesley Musgrove

To view all the changes in an un-popped stash:

要查看未弹出的存储中的所有更改:

git stash show -p stash@{0}

To view the changes of one particular file in an un-popped stash:

要查看未弹出存储中某个特定文件的更改:

git diff HEAD stash@{0} -- path/to/filename.php

回答by Bruce

Beyond the gitk recommendation in Is it possible to preview stash contents in git?you can install tigand call tig stash. This free/open consoleprogram also allows you to choose which stash to compare

除了 gitk 建议之外,是否可以在 git 中预览存储内容?您可以安装tig并调用tig stash. 这个免费/开放的控制台程序还允许您选择要比较的存储

回答by seanf

I use this to see all my stashes with colour diff highlighting (on Fedora 21):

我用它来查看我所有带有颜色差异突出显示的隐藏(在 Fedora 21 上):

git stash list | 
  awk -F: '{ print "\n\n\n\n"; print 
$ git stash list

stash@{0}: WIP on dev: ddd4d75 spelling fix

stash@{1}: WIP on dev: 40e65a8 setting width for messages

......

......

......


stash@{12}: WIP on dev: 264fdab added token based auth
; print "\n\n"; system("git -c color.ui=always stash show -p " ); }' | less -R

(Adapted from Git: see what's in a stash without applying stash)

(改编自Git:在不应用 stash 的情况下查看 stash 中的内容

回答by hlongmore

When this question was first asked, this may not have been an option, but, if you use PyCharm, you can use the UnStash Changestool (VCS->Git->UnStash Changes...). This allows you to view the list of stashed changes, as well as pop, drop, clear, or apply (into a new branch if desired):

当第一次问这个问题时,这可能不是一个选项,但是,如果您使用 PyCharm,则可以使用该UnStash Changes工具 (VCS->Git->UnStash Changes...)。这允许您查看隐藏更改的列表,以及弹出、删除、清除或应用(如果需要,进入新分支):

Unstash Changes Window

取消隐藏更改窗口

and view the changed files per stash:

并查看每个存储的更改文件:

Paths Affected Window

路径影响窗口

as well as diffs per file. In the diffs you can cherry-pick individual changes to apply from the stashed changes to the working branch (using the left-pointing chevron):

以及每个文件的差异。在差异中,您可以从隐藏的更改中挑选要应用到工作分支的单个更改(使用指向左的 V 形):

enter image description here

在此处输入图片说明

回答by Vishvajit Pathak

You can view all stashes' list by the following command:

您可以通过以下命令查看所有 stash 的列表:

git stash show -p stash@{3}

Newest stash is the first one.

最新的藏品是第一个。

You can simply select index nof stash provided in the above list and use the following command to view stashed details

您可以简单地选择n上面列表中提供的存储索引,然后使用以下命令查看存储的详细信息

git stash show -p stash@{n}

Similarly,

相似地,

git diff HEAD stash@{n} -- /path/to/file

You can also check diff by using the command :

您还可以使用以下命令检查差异:

git stash show -p stash@{0} > stash.txt

回答by Walterwhites

yes the best way to see what is modified is to save in file like that:

是的,查看修改内容的最佳方法是像这样保存在文件中:

git stash list

回答by Bharat

View list of stashed changes

查看隐藏更改的列表

git stash show -p stash@{0} --name-only

For viewing list of files changed in a particular stash

用于查看特定存储中更改的文件列表

git show stash@{0} path/to/file

For viewing a particular file in stash

用于查看存储中的特定文件

##代码##