Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need to delete a commit to a fork

Tags:

git

github

OK, I did something stupid.

  • I forked a repo I am supposed to contribute to.
  • So I then literally created a file called "blafile" to check I can commit (obviously I did not understand what a fork is) and committed with a message "check I can commit".
  • I pushed to my github forked repo and forgot about it.
  • I started fixing a bug on the next day.
  • I committed my fix and pushed to my forked repo with message "fixed bug xyz".

Now I wanted to issue a pull request, and all of a sudden I see my "check I can commit" commit. I'd rather not like that to appear on the pull request. :)

Can I entirely delete that commit? Can I issue a pull request on a single commit or will it pull all my commits?

I know I can locally git reset --hard HEAD~1(it's a small fix I could redo quickly) but that only fixes my local repo, not my github (forked) repo.

like image 785
transient_loop Avatar asked Mar 26 '13 22:03

transient_loop


1 Answers

Lots of options.

The best option is probably to make a new branch and cherry-pick your fix into that branch:

git checkout -b my-fix-branch origin/master
git cherry-pick master
git push -u origin my-fix-branch

then do a pull request from my-fix-branch on GitHub. (This assumes your working branch is named master, based off the remote master; change the branch names as appropriate).


IF nobody has pulled or cloned your fork, you can rewrite history forcefully. Do git rebase -i HEAD~2 and delete the offending commit, then git push --force. This will break any other repo based on your fork, so do not do this if you suspect anyone else is using your repo.

like image 117
nneonneo Avatar answered Oct 07 '22 18:10

nneonneo