Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git diff against a stash

Tags:

git

git-stash

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!

like image 869
James Andino Avatar asked Oct 06 '11 16:10

James Andino


People also ask

How do you diff against stash?

If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master , you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, ...

What is the difference between stash and git?

The git commit and git stash commands are similar in that both take a snapshot of modified files in the git working tree and store that snapshot for future reference. The key differences between the two are as follows: A commit is part of the public git history; a stash is stored locally.

How do I see stash changes in git?

The Git stash list command will pull up a list of your repository's stashes. Git will display all of your stashes and a corresponding stash index. Now, if you wish to view the contents of a specific stash, you can run the Git stash show command followed by stash@ and the desired index.

How do I pop a specific stash?

To pop a specific stash in git, you can use the git stash apply command followed by the stash@{NUMBER} command. command. It will show the list of stashes you have saved.


2 Answers

See the most recent stash:

git stash show -p

See an arbitrary stash:

git stash show -p stash@{1}

From the git stash manpages:

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).

like image 98
Amber Avatar answered Oct 16 '22 12:10

Amber


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.

like image 399
czerasz Avatar answered Oct 16 '22 13:10

czerasz