0

I have this linear series of commits:

A, B, C, D, E, F, G
                  ^
                 HEAD

A couple of files in commit D have errors, which need to be fixed in commit D and all following commits (E, F, and G). This is a private repository, so I can just overwrite everything.

Almost all of my Git experience is

git add --all :/
git commit -m 'Commit msg'
git push -u origin branchname

This question

discusses rebasing, but that seems to be related to merging two branches. I'm hesitant to experiment, for fear of permanently damaging the repository. Perhaps that implies I should be branching and then merging...

What is the proper way of going about this?

Community
  • 1
  • 1
aliteralmind
  • 19,847
  • 17
  • 77
  • 108
  • Rebasing can be used for this, too; just try what’s given in the question you linked to (but stage your changes with `git add` before `git commit --amend`, as stated in the answer). – Ry- Dec 21 '14 at 21:01
  • possible duplicate of [editing commits with git rebase](http://stackoverflow.com/questions/21211767/editing-commits-with-git-rebase) – try-catch-finally Dec 21 '14 at 21:12

1 Answers1

1

Assuming your current branch is master,

git checkout $D
# fixup file here
git commit -a --amend  # fixup in added commit (w/o --amend) is also a good option
git rebase @ master  # <-- or git rebase HEAD master, same thing

Be aware that all the rebased or amended commits in $D^..master will be rewritten, but no other children of $D^ -- if you have branch points downstream of $D you'll have to rebase those onto the new history separately.

This is pretty much identical to the rebase --interactive suggestions in linked answers/questions, but when only one thing needs fixing up I find it more pleasingly direct to just do it myself.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • what does the `$` signify in your answer? – M.M Dec 22 '14 at 01:13
  • It's shell parameter-expansion syntax, I meant it here as "however you want to refer to commit D". – jthill Dec 22 '14 at 01:20
  • Both the marked-as-duplicate question and the one I linked to in the question-post use `git rebase --continue`. Can you explain the difference between that and `git rebase @ master`? Thank you, @jthill. – aliteralmind Dec 22 '14 at 14:23