General Question

Vincentt's avatar

Can anybody guide me in rewriting a commit in Git?

Asked by Vincentt (8094points) October 17th, 2008

I have this Git repository on my computer, and I’d like to do another push to the central server. However, I made a mistake in one of the files in a previous commit that I cannot publish online. Thus, I want to rewrite that commit.

However, I tried doing it on my own using the Git manual, but I didn’t manage. So Fluther is my last hope – can anybody (e.g. through PM’s) guide me through the process of rewriting history?

Observing members: 0 Composing members: 0

6 Answers

damien's avatar

I think git-filter-branch is what you need here, but I’m not entirely sure. I know that can completely remove a file, but I’m not so sure about how you’d just remove parts of a particular file.

damien's avatar

Some of this and this might help, too (same page, just different sections).

**edit** Sorry, just re-read your question… Was it these parts of the git manual that you were struggling with or the more technical docs?

Vincentt's avatar

Haha, those two latter pages were exactly the pages that I tried and failed with :P

Note that I don’t want to filter my commit so much as to checkout the old commit, edit it and recommit that at the same point in history. The problem is that I’ve also edited that document in a later commit. Perhaps there’s some way I can first delete it from that later commit, then edit it in the first one, and then re-add it in the later one with the newer edits?

damien's avatar

Sorry – It wasn’t until I posted all the links to git docs that I read that you said you were struggling with git docs! My eyes are painted on, you see ;)

Have you actually pushed the bad commit or is it still just local?

To be honest, I don’t know how you’d go about doing what you’re explaining there (assuming you have pushed it to the remote branch). If it was me, unless there was a need to keep the history of the file, I’d be tempted to just remove the file from the tree completely (and it’s history) and then re-add it they way you want the file to be.

Since that does completely defeat the purpose of SCM, I’d then keep sheepishly quiet about it and hope no-one finds out. Perhaps they need to add a push-under-the-rug command to complement the normal push :P

Sorry I’m not much use!

andrew's avatar

bzr uncommit; bzr commit -m… oh… wait, that’s right.

Vincentt's avatar

@damien – I haven’t pushed it to the remote branch yet, it’s all local. If I can’t find anybody to help I guess I’ll do what you suggested ;-)
(It’s an image, so I guess it’s better warranted – otherwise I could manually solve a merge conflict ;-)

@andrew – I know of git commit—amend, that works great and I suppose quite similar to bzr uncommit; bzr commit – m. However, I can’t see how Bazaar makes it easier to fix a mistake in a file further back in history that has additional changes closer to present ;-)

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther