Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show stashes in gitk without `--all` option?

Tags:

git

gitk

I'm working on a huge git repository that is too large to make viewing all remote branches practical. Thus I don't want to use gitk --all. However, I do like to view other things like my local branches, which I can do with gitk --branches.

Is there a way to also view any stashes?

like image 205
Jaap Eldering Avatar asked Jan 16 '18 13:01

Jaap Eldering


People also ask

How do I see all stashes in git?

Git Stash List. 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.

Which command is used to list stashes?

One you have identified the entry in which you are interested, you likely want to see what is in that stash. This is where the git stash show command comes in. This will display a summary of file changes in the stash.

What is the command to see all the saved stashes in a repository?

We can track the stashes and their changes. To see the changes in the file before stash and after stash operation, run the below command: Syntax: $ git stash show.


1 Answers

UPDATE with more concise log command...

You might notice that even with --all, gitk does not list all stashes. This is because stashes are not distinct refs; they are reflog entries on the single ref stash.

You can still list multiple stashes, such as by saying

gitk stash@{0} stash@{1}

but only the most recent stash commit will be shown as having a ref pointed at it (which is true; again, the rest are reflog entries).

To automatically include every stash, you can do something like this

gitk `git stash list --format=%H`

This may not help much, though, as a stash's full history would be shown. (And again, only the most recent stash would show with a ref pointed at it, so spotting the others in a long history might not be easy.)

With git log you could do something like

git log `git rev-parse $(git stash list --format=^%H^)` `git stash list --format=%H`

or, more concisely,

git log `git rev-parse $(git stash list --format=%H^..%H)`

to cut the history short and show only stash commits, but gitk doesn't seem inclined to honor the ^<commit> exclusions. Also -n 1 doesn't work because that limits the total number of commits output, not the number per ref (and besides, gitk then decides to be helpful by filling in the history anyway).

So I'm not entirely sure you can do what you want with gitk. But on the other and, the graph that gitk draws would just be a disjointed mess anyway, so maybe the log approach could be adapted to suit your needs?

like image 74
Mark Adelsberger Avatar answered Sep 23 '22 12:09

Mark Adelsberger