user3730179
user3730179

Reputation: 121

git delete a commit from pull request

Warning: Git newbie

I know the basic git commit and pull, push and currently using source tree for github. Right now I am working on a project where i forked a repo. and accidentally optimized over 300+ images. Good thing is I separated all the images in one commit. The client requested a pull request which I have done. He also said that I should not have optimized these images and to delete this commit from the pull request.

The commit with the images has been pushed many commits ago so it is hard to wrap my head around this. What I thought would work is if i reset the repo back to this commit and delete the images and push again. but by deleting the images, i reset the images so they would be back to what they originally were and when i pushed the changes, it doesn't show anything was changed with the images with the new commit.

Not sure if I am making myself clear. What is the best way to go about this?

Upvotes: 2

Views: 5083

Answers (1)

user2683246
user2683246

Reputation: 3568

1) Find the hash of the commit with the images. Suppose it is COMMIT. Then in the console type in (note to add ^ after the commit hash):

git rebase -i COMMIT^

Git will open an editor. Delete the first line, corresponding to the commit with images. Save the file and exit the editor. Git will rewrite your history and exclude the commit with images. Then push your new history to the remote repo adding --force option:

git push --force origin master

Make pull request.

2) Instead of interactive rebase you can use this in your case:

git rebase --onto COMMIT^ COMMIT master

3) And you can also leave your history as it is and cancel just that commit:

git revert COMMIT

Upvotes: 2

Related Questions