Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check the source code of stashed files without pop them in git?

Tags:

git

git-stash

I have some stashed files in git, but I do not want to git stash pop it, because sometime it alert merge message, I do not want to do merge in order to see the source code in stashed files, is there a way of doing that?

like image 393
user2131316 Avatar asked Sep 16 '13 16:09

user2131316


People also ask

How do I see stashed data 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 get the stashed code?

Retrieve Stashed Changes To retrieve changes out of the stash and apply them to the current branch you're on, you have two options: git stash apply STASH-NAME applies the changes and leaves a copy in the stash. git stash pop STASH-NAME applies the changes and removes the files from the stash.

How do I access stashed changes in git?

Retrieving stashed changes You can reapply stashed changes with the commands git stash apply and git stash pop . Both commands reapply the changes stashed in the latest stash (that is, stash@{0} ). A stash reapplies the changes while pop removes the changes from the stash and reapplies them to the working copy.


2 Answers

Assuming you want the latest stashed entry,

git show stash@{0}:pathname

Two aspects of this syntax are explained in their respective manual pages:

  • The <rev>:<path> thing is explained in the gitrevisions(7) manual page (consider reading it in its entirety — it will teach you certain convenient things to use later on).
  • The stash@{<n>} syntax to access stash entries is explained in the git-stash(1) manual page.
like image 135
kostix Avatar answered Sep 19 '22 20:09

kostix


In order to get back a stashed code without remove it of the stash list you can use

git stash apply

to recover the last stashed code, but I believe you just want to see the diff, you can use

git diff stash@{0}

which is a simple command to diff the stashed code at the first position.

Using git stash list you can take a look at which position the stashed code you want to see exists and then run git diff stash@{position} with the proper position.


EDIT :

As stated in the comments there is another command that could help, if you want to see the whole file in a stashed code you may create a branch with the stashed code and browse at will using the following command

git stash branch <branchname> [<stash>]
like image 31
Miguelgraz Avatar answered Sep 19 '22 20:09

Miguelgraz