Is it possible to remove a commit on github, without deleting the whole fork and starting it all again?
For example , if I already commit a file and then decide to make another change. Or does it even matter. If I up load the same file again as a newer version with that produce a clean PR ?
Thanks to anyone who understands this metter than I do.
Yes: what you need is a combination of “fixup” and “force push”. Here’s my workflow:
git commit -m "Do a thing"
git push
// Realize I forgot something, edit the file, save it
git add theFile.py
git commit --fixup HEAD
git rebase -i HEAD~2
// Make sure the second line in the rebase operation is a "fixup" operation, save, close
git push -f
This will replace the original commit with a different one that includes your “fixup”. There are other possible workflows, this is just the one I think is easiest.
My question was about github, because I could not find a way to do it. But seeing all that jive, I guess that answers why I cannot find a button to do it on github.
Thanks for your detailed reply , it may come in useful one day.
Well, for just changing the last commit, you can just ‘git commit --amend’. But I guess you knew and it was for demo.
One point. As you use ‘–fixup’ your rebase can be ‘git rebase -i --autosquash HEAD~2’ so it will automatically reorganize and change appropriate commits to fixup.