Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view stash date/timestamp next to stash id?

Tags:

git

git-stash

Using git stash list shows me the list of stashes with their IDs. Using git stash list --date=local or git stash list --date=relative gives me their times, but I have no idea what their corresponding ID is.

I want to acquire a stash at a certain time.

like image 461
LazerSharks Avatar asked Jul 28 '15 20:07

LazerSharks


People also ask

How do I find my stash date?

If you want to show the actual date, rather than a relative time then replace %(cr) with %(ci) . Show activity on this post. git show stash@{0} also prints out the date, along with the other information.

How do you show the details of a stash as a difference?

Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no is given, shows the latest one. 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).

How can I see my stash changes without applying?

git stash show -p stash@{0} --name-only shows just the names of the files (not the contents) in your first stash. @mrgloom If you want to see the stashed changes for a single file, then something like git diff stash@{0}^! -- file. txt will do it.

How do I view stash logs?

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.


1 Answers

git stash list simply runs git log with a particular set of options:

list_stash () {         have_stash || return 0         git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash -- } 

The $@ part inserts whatever additional options you've specified (none by default, but --date=relative in this case).1

When you use --date=relative this modifies the output from %gd: instead of a short reflog with an index, you get a short reflog with a relative time stamp:

$ git stash list stash@{0}: ... $ git stash list --date=relative stash@{4 minutes ago}: ... 

The solution in this case is to use your own explicit format, rather than just letting --date=relative modify how %gd gets displayed. For instance:

$ git stash list --format='%gd (%cr): %gs' stash@{0} (4 minutes ago): ... 

(%cr inserts the commit's committer time stamp, in relative format—this makes sense once you know that all git stash does is make a couple of commits for you, with the commits being stored on the special stash ref instead of on a branch).


1On reviewing this answer, I note that the --first-parent and -m arguments (literally present in the git stash code) seem redundant at first, because of the -g argument. The -g argument to git log tells it to look only at the reflog, rather than the commit history, in which case, --first-parent means nothing. Meanwhile -m tells git diff to split a merge commit, but we're looking at commit logs, not diffs, so what is this doing here?

The answer is that git log can show a patch, for which it runs git diff, so if you give -p as an argument, the --first-parent -m limits this diff to comparing the commit to which the stash reflog points against its first parent. The stash bag commit to which the reflog entry points is the work-tree commit, whose first parent is the original commit on which the stash-bag hangs. (Its second parent is the index commit and its third parent, if present, is the all or untracked files commit.) So these options are there to make git stash list -p diff the stash's work-tree commit against the commit that was current when the stash itself was made.

This is clever, but quite obscure! :-)

like image 84
torek Avatar answered Sep 24 '22 10:09

torek