nowox
nowox

Reputation: 29096

What solution to amend a Pull Request?

I have made a PR on GitHub (Enterprise) with few commits. My reviewers identified a small mistake on one commit:

* a401341c Did this (HEAD -> foo)
* 08e97f86 Did that
* 616cd4ad Done that
* f3c6151b Accomplished this
* 1af6e74f Fix this <-- Error there
* a099fc19 Finished this
* ab726eb3 Cherry-picked this (master, origin/master)

The first solution is to revert all commits after 1af6e74f because I cannot just revert it without conflicts, then reapply all the commits with the correction:

* 0c99cf29 Reapply Did this (HEAD -> foo)
* 8806f36b Reapply Did that
* 572e1122 Reapply Done that
* 64ea3dc8 Reapply Accomplished this
* 81e20976 Fix this (this time correctly)
* d78a4534 Revert Fix this <-- Error there
* c0d817a9 Revert Accomplished this
* ed2bb3b2 Revert Done that
* ea34322a Revert Did that
* f81b78a3 Revert Did this
* a401341c Did this
* 08e97f86 Did that
* 616cd4ad Done that
* f3c6151b Accomplished this
* 1af6e74f Fix this <-- Error there
* a099fc19 Finished this
* ab726eb3 Cherry-picked this (master, origin/master)

Then git push to update my PR.

The second solution would involve a git push -f

git checkout 1af6e74f 
git commit --amend -am "Fix this (with corrections)"
git rebase --onto a401341c f3c6151b HEAD # Not sure this will work as written
git branch -f foo HEAD
git push -f

Is the former solution a good solution and the latter always a bad one?

Upvotes: 0

Views: 58

Answers (1)

LeGEC
LeGEC

Reputation: 51850

Question :

What is the diff between your old branch and the new branch (git diff a401341c 0c99cf29) ?
Does it look like a reasonable patch, which indicates clearly enough how the bug was fixed ?


If it does, just take the new content and commit this as a new commit on top of your old branch :

git checkout foo

# just to be on the safe side : work on a new temporary branch
git checkout -b wip

# go back to the old sate :
git reset --hard a401341c   # <- original "Did this" commit

# get the content from new branch :
git checkout 0c99cf29 .   # <- don't forget the "."

# check that it matches what you expect :
git diff [--cached] ...
git difftool -d [--cached] ...

# if OK : commit !
git commit


# make your local "foo" branch point to this commit :
git checkout foo
git reset --hard wip
git branch -d wip

# push :
git push origin foo

Upvotes: 1

Related Questions