Git diff against a stash

2019-01-08 02:14发布

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!

标签: git git-stash
11条回答
Root(大扎)
2楼-- · 2019-01-08 02:52

This works for me on git version 1.8.5.2:

git diff stash HEAD
查看更多
三岁会撩人
3楼-- · 2019-01-08 02:52

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)

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.

查看更多
叼着烟拽天下
4楼-- · 2019-01-08 02:55

She the list of stash

git stash list 
stash@{0}: WIP on feature/blabla: 830335224fa Name Commit
stash@{1}: WIP on feature/blabla2: 830335224fa Name Commit 2

So get the stash number and do:

You can do:

 git stash show -p stash@{1}

But if you want a diff (this is different to show the stash, that's why I write this answer. Diff consider the current code in your branch and show just show what you will apply)

You can use:

git diff stash@{0}

or

git diff stash@{0} <branch name>

Another interesting thing to do is:

git stash apply
git stash apply stash@{10}

This applies the stash without removing it from the list, you can git checkout . to remove those change or if you are happy git stash drop stash@{10} to remove a stash from the list.

From here I never recommend to use git stash pop and use a combination of git stash apply and git stash drop If you apply a stash in the wrong branch... well sometimes is difficult to recover your code.

查看更多
戒情不戒烟
5楼-- · 2019-01-08 02:56

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.

查看更多
太酷不给撩
6楼-- · 2019-01-08 02:59

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.

You can use:

git diff stash@{0} master

To see all changes compared to branch master.


Or You can use:

git diff --name-only stash@{0} master

To easy find only changed file names.

查看更多
迷人小祖宗
7楼-- · 2019-01-08 02:59

If you have tools for diff (like beyond compare)

git difftool stash HEAD
查看更多
登录 后发表回答