Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git, made a pull-request but found a bug in my code, how to fix it?

I made my first pull-request not long ago, and I found a bug in the code.(meh)

I don't want to make a new branch and commit/push/pull request the new branch since this must have been in the first pull-request.

Do I drop the pull-request and submit a new request?
Are there other ways?

EDIT

I did 'git commit --amend' but I can't push it.

I see my latest commit is now #B, while the original commit was #A and github webpage shows my pull requests is pointing at #A

I did 'git push my_github_fork MyWork_branch but it says Everyhing-up-to-date.

I tried giving -f option to it but no avail.

like image 653
eugene Avatar asked May 22 '13 13:05

eugene


2 Answers

If the repo has not been yet pulled, you can simply fix the bug with a further commit, which will be pulled.

like image 197
Claudio Avatar answered Sep 28 '22 05:09

Claudio


If you would like to keep your pull-request clean, I would recommend rebasing the commits in your branch so that the bug isn't even visible, and force-pushing your branch to GitHub.

If you're fixing your latest commit, this is as simple as amending it:

git commit --amend

GitHub will automatically update the commits in your pull-request with whatever is in that branch, so when this is viewed by the developers in the other repository, they will simply see the commits that you want them to see.

I always try to make sure that commits in git tell some kind of story -- it should be clear what you're doing from the commit history. When a pull-request gets littered with mistakes and later commits that fix them, it makes it really hard to understand that story.

I have been on the receiving-end of many a pull-request that was messy and unclear. I definitely recommend rebasing the branch to keep everything crystal clear.

like image 25
Sam Fen Avatar answered Sep 28 '22 05:09

Sam Fen