0

I'm trying to execute a rebase of my feature branch onto a development branch that has changed since I started my work. Here's the commit history prior to starting my rebase (ellipsis added by me):

$ git log --oneline
21c72f6 (HEAD -> feature, origin/feature) Mattermost loggin...
fade238 GUI message typ...
daaeb54  Message gramma...
bf09129 Error handling for...
94eb0de Notes in comment...
379a6c9 Cleanup
057a7d5 Update `check_fs...
edd44b4 Update `check_p...
5639c61 Update `sse_con...
0000000 <last_commit_before_my_feature_branch>

Of my 9 commits, 3 contain the real feature implementation. The other 6 are fairly inconsequential tidying, so I'd like to squash those into a single "cleanup" commit. I've also swapped a couple of orderings. Here is my git-rebase-todo file:

pick 5639c61 Update `sse_con...
pick edd44b4 Update `check_p...
pick bf09129 Error handling for...
edit 379a6c9 Cleanup
fixup 057a7d5 Update `check_fs...
fixup 94eb0de Notes in comment...
fixup daaeb54 Message gramma...
fixup fade238 GUI message typ...
fixup 21c72f6 Mattermost loggin...

I'm using vsCode's GitLens extension to kick off and step through the rebase.

I want to see my edited / fixed up / squashed changes before applying them as a new commit.

Here's the command used to start the rebase (from the vsCode terminal): git rebase -i dev

Upon arriving at my first edited commit - 379a6c9 Cleanup - I'd expect to find a "Changes to be committed" list showing changes between the previous commit - bf09129 Error handling for... - and the upcoming edited / squashed / fixed-up commit (similar to how you might when using git cherry-pick --no-commit), but unless I hit a conflict, the only things I get are "Continue" in vsCode or the status of the rebase in the CLI:

$ git status
interactive rebase in progress; onto 1aeafea
Last commands done (4 commands done):
   pick bf09129 Error handling for...
   edit 379a6c9 Cleanup
  (see more in file .git/rebase-merge/done)
Next commands to do (5 remaining commands):
   fixup 057a7d5 Update `check_fs...
   fixup 94eb0de Notes in comment...
  (use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'feature' on '1aeafea'.
  (use "git commit --amend" to amend the current commit)
  (use "git rebase --continue" once you are satisfied with your changes)

nothing to commit, working tree clean

I'm not sure if this is an idiosyncrasy of vsCode / GitLens or simply user error.

Further, I'm not sure what the state is when I hit this step. Has Git done additional "stuff" in the background? Has the "squashing" of the subsequent commits already happened? What is the correct way to describe this state in Git parlance? (I think this response may answer some of these questions, but I'm struggling to reconcile the differences in context.)

Collin
  • 254
  • 1
  • 9

1 Answers1

0

It may be counterintuitive but git rebase -i walks the todo list from top to bottom. So first it stopps at 379a6c9 Cleanup that you marked for editing. If will do the fixups at the end and not other way round.

If you want to preview what would the final commit be, do a diff up to the commit you are fixing everything up to:

git diff 379a6c9^ # one before the "Cleanup" commit
svlasov
  • 9,923
  • 2
  • 38
  • 39
  • Thanks for your response! I just realized I did not provide the initial `git log` or indicate that I had GitLens' "Oldest first" view(?) option enabled, which I think addresses your first point about it going top to bottom. I've updated the question accordingly.... – Collin May 31 '23 at 21:18
  • Now I see that you also reordered the commits, that complicates it. Git cannot give you the preview because the final result is unknown (e.g. your commits may not apply in that order). I recommend you to create a new branch, do the rebase there, check that you are happy with result and delete the old branch. – svlasov May 31 '23 at 21:43
  • Hi, sorry for the confusion. I've updated it again to show the exact `git-rebase-todo` instructions. I'm not sure I understand what you mean by "preview" - I was under the impression that these rebase "todo" instructions were functionally the equivalent of `git cherry-pick 5639c61 edd44b4 bf09129 `, then `git cherry-pick -n 379a6c9`, `git cherry-pick -n 057a7d5` (and so on until reaching `21c72f6`), at the end of which I would have commits, 5639c61, edd44b4, and bf09129, plus the staged changes from the remaining commits (which I can view in my diff editor). – Collin May 31 '23 at 22:25