Elad Aharon
Elad Aharon

Reputation: 570

How to git rebase -i edit and see past commits changes

Usually I'm editing old commits with git rebase -i HEAD~<number of commits I added> put edit on the commits I want to edit, make the change, adding files and git rebase --continue.

Is there a way to edit commits with rebase but to see the past commit changes? it will be much easier to spot the places I want to fix there, VScode mark the lines for me.

example: let's say I have committed commitA, commitB, commitC (HEAD at commitC). now I would like to edit commitA. I'm git rebase -i HEAD~3 and put edit on commitA. now I'm in the middle of my rebase but I want commitA changes to appear as changes, the situation is making me write my fix when commitA changes are already committed.

if there is an alternative way of fixing past commit and having that commit changes as staged that would be great.

Thanks in advance!

Upvotes: 11

Views: 4160

Answers (1)

Elad Aharon
Elad Aharon

Reputation: 570

o.k seems it's easier than I thought! just follow those steps: let's say I want to edit 5 commits back:

  1. git rebase -i HEAD~5
  2. change pick to edit on the commits you want to edit.
  3. your interactive rebase will start, if you want to see current commit changes type git reset HEAD~1 since the commit already there, were just resetting it.
  4. make your changes.
  5. git add <files of your change and past commit files> or just git add -u to add all tracked files.
  6. git commit
  7. git rebase --continue

happy gitting :)

Upvotes: 12

Related Questions