0

I used a very bad log template and has issued git push for that commit. How can I modify or delete this log entry?

1 Answer 1

3

The answer depends on whether or not other people have pulled your commit. If they have, then you're stuck with the bad template (or at least getting every local pull of the commit corrected probably isn't worth your time). If others haven't pulled it...

If it's the most recent commit, you can use git commit --amend.

If it's a commit a certain number in the past (call it commit abcd1234), then you can use git rebase:

git rebase -i abcd1234~1

In the interactive screen, change pick to reword for that commit, and leave the rest the same. The rebase will continue to that commit, then pause, allowing you to reword the commit message.

In either case, you'll need to "force push" the rebased branch up:

git push --force origin <branch> ;# using the `--force` flag
git push origin +:<branch> ;# same as above, just different syntax
Sign up to request clarification or add additional context in comments.

8 Comments

Actually I am sure someone has pulled my commit. So is that to say it is NOT possible to fix this commit message?
@deepsky No, it is possible; it's just a serious pain. Both commands rewrite SHA1 hashes, which means your collaborators will have divergent branch histories. Unless they reset (which interrupts work in progress), you'll end up with redundant histories. If this sounds complex, it is. Unless the commit format is really grievous, it's probably not worth fixing.
@Christopher: They can rebase, which does not interrupt work in progress. But it's still action they need to do and at least a little bit understand to be able to do.
I think there is only 1 people pulled this commit and this commit message is really bad. So do I just need to ask him to do a new clone?
The repository can be configured to refuse forced pushes and if it's not your repository, you may not be able to bypass that check. In which case you can't fix it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.