问题
I'm in the middle of an interactive rebase. Is there a command that shows the list of commits that were initially selected when I started the rebase?
回答1:
During the interactive rebase, git updates files in your .git
directory under the sub-directory rebase-merge
(the exact path has changed in various versions of git, as I recall; I'm looking at git 2.0.x behavior right now).
In that directory are the files done
and git-rebase-todo
. These are not quite what you asked for: they're the finished parts and the not-yet-done parts, not the "pick" commands that were presented to you initially, nor necessarily the commands you've gone with (if you skipped some). There's also a git-rebase-todo.backup
, which contains what was in the "todo" list after you edited it. I'm not sure if you wanted the complete list of revs or the list you chose at the time you exited the editor, but if it's the latter, the backup file is the right thing.
There is also a reference named ORIG_HEAD
that points to the tip of the (original) branch that is being rebased, and .git/rebase-merge/head-name
which contains the name of the branch (and the branch is not moved until the rebase is complete). You could use this, plus some of the other files, to reconstruct the originally-offered "pick" list.
回答2:
Note that Git 2.3.0 (February 2015) will display the number of "todo" during an interactive rebase.
See commit 97f05f4 by Onno Kortmann (onnokort)
Show number of
TODO
items for interactive rebaseDuring '
rebase -i
', one wrong edit in a long rebase session might inadvertently drop commits/items.
This change shows the total number ofTODO
items in the comments after the list.
After performing the rebase edit, total item counts can be compared to make sure that no changes have been lost in the edit.
The git-rebase--interactive.sh now includes (using git stripspace):
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
cat >>"$todo" <<EOF
$comment_char Rebase $shortrevisions onto $shortonto ($todocount TODO item(s))
Note that with Git 2.16 (Q1 2018), an interactive rebase will be able to produce the todo list with a single-letter command names (if the configuration variable rebase.abbreviateCommands
is set).
See commit 1795993, commit d8ae6c8, commit 0cce4a2, commit 313a48e, commit d80fc29, commit 8dccc7a (05 Dec 2017), and commit 7dcbb3c, commit f3b633d, commit 946a9f2 (03 Dec 2017) by Liam Beguin (Liambeguin).
(Merged by Junio C Hamano -- gitster -- in commit 0da2ba4, 27 Dec 2017)
rebase -i
: learn to abbreviate command names
git rebase -i
already know how to interpret single-letter command names.
Teach it to generate the todo list with these same abbreviated names.
The git rebase config man page will read:
rebase.abbreviateCommands::
If set to true,
git rebase
will use abbreviated command names in the todo list resulting in something like this:------------------------------------------- p deadbee The oneline of the commit p fa1afe1 The oneline of the next commit ... -------------------------------------------
instead of:
------------------------------------------- pick deadbee The oneline of the commit pick fa1afe1 The oneline of the next commit ... -------------------------------------------
Defaults to
false
.
Note that Git 2.21 (Q1 2019) makes "git stripspace
" usable outside a git repository, even in "-s" or "-c" mode.
stripspace
: allow-s
/-c
outside git repositoryv2.11.0-rc3~3^2~1 (
stripspace
: respect repository config, 2016-11-21, Git v2.11.0-rc3) improvedstripspace --strip-comments
/--commentlines
by teaching them to read repository config, but it went a little too far: when runningstripspace
outside any repository, the result is$ git stripspace --strip-comments <test-input fatal: not a git repository (or any parent up to mount point /tmp)
That makes experimenting with the stripspace command unnecessarily fussy.
Fix it by discovering thegit
directory gently, as intended all along.
来源:https://stackoverflow.com/questions/25399907/git-show-list-of-commits-during-interactive-rebase