Git reload interactive last n commits

I made a bunch of fuzzy commits in my function branch and now I want to change the order and partially squander the belonging records visually. I believe that the solution is somehow in interactive Git, but how to call it?

$ git rebase --interactive --onto <the-ID-of-the-first-commit-to-rewrite> 

just pops VI using

 noop 

followed by commented information. After exiting, my head reset to the specified commit.

How to properly initiate an interactive rebase to change commits from a specific commit?

+17
source share
4 answers

you should use

 git rebase --interactive <sha1> 

where <sha1> should not be the sha of the first commit you want to rewrite, but the sha of the commit just before.

if your story looks like this:

 pick 43576ef last commit ... pick 5116d42 first commit to rewrite pick cb85072 last good commit 

then you can specify various ways to indicate the commit you want to reinstall:

 git rebase -i cb85072 git rebase -i 5116d42^ 

Where

  • ^ means commit immediately before.
  • -i for short --interactive
+25
source

You can also backtrack from the last commit with a number of commits. For example, if you want to reinstall the last 5 commits, you can use this command: git rebase -i HEAD~5 .

+16
source

I skipped the rebase action in your statement:

 git rebase -i <id-of-commit> 
+1
source

To view and rewrite the latest n commits, use:

 git rebase -i HEAD~n 

p, pick = use commit

f, fixup = like "squash", but discard this commit log message

https://www.freecodecamp.org/forum/t/how-to-squash-multiple-commits-into-one-with-git-squash/13231

+1
source

Source: https://habr.com/ru/post/1013749/


All Articles