4

I am having the hardest time trying to figure out how to edit a git commit message that has already been pushed to GitHub. I could have sworn that in the past I have used this same command to edit already pushed git commits and have no issues what so ever. The problem that I'm having right now is when I run git rebase --interactive <SHA of commit> I get something that looks like this...

noop

# Rebase 5d8e041..5d8e041 onto 5d8e041 (1 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

When I run the exact same command but with a git commit that hasn't been pushed up to GitHub yet, everything works perfectly fine. Is there something I'm missing? Like I said before I could have sworn that this at one time worked perfectly fine with pushed and unpushed commits.

Thanks so much for your help I greatly appreciate it.

Alex Lowe
  • 783
  • 3
  • 20
  • 43

4 Answers4

2

The final answer to my question of why git rebase -i <sha> isn't bringing up a preferred editor to even choose whether to reword a commit message or any other option like. The answer was that I was using the 64bit architecture instead of the 32bit architecture. Now, I honestly don't know why this is but I did find a post on GitHub that was talking about certain commands failing on the 64bit architecture, specifically git rebase and certain git merge operations according to that post. It also said that...

leaves incomplete git operation and also adds a file on disk, sh.exe.stackdump with STATUS_STACK_OVERFLOW + register dump.

I wasn't getting this error popping up in the git console though. I was getting when I opened my project in SmartGit, which is just a GUI for git. This would happen when I right clicked on the git message before the git commit message that I actually wanted to rebase and then went to Rebase Interactive From. It wouldn't instantly through the error instead, it would try for 10 seconds and then through the error.

So at this point, I've figured out what caused my problem but I just don't know why yet. Why would a 64bit architecture version of git run differently than a 32bit one? The mind boggles. If anyone has a specific reason why this is happening please go ahead and just edit my post.

Alex Lowe
  • 783
  • 3
  • 20
  • 43
1

As documented here, a "reword" will allow you to change a past commit message (provided you rebase on top of the parent commit you want to change, as first reported in -- upvoted -- nnovich-OK's answer).

But if the commit was already pushed to GitHub, you will have to do a git push --force (or --force-with-lease, if it is not ignored)


When I run git rebase -i 5d8e041~1 I got Current branch master is up to date

Check if addinf the --force option would help.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Issue isn't related to pushed/not-pushed status of commit. You're trying to edit exactly the last commit on the branch. To do this via rebase you should invoke git rebase --interactive <SHA of PARENT commit>, but you use hash of commit itself instead. Rebase is supposed to edit all descendants of specified commit, but you provided commit with no descendant, so git shows noop in the list of possible changes.

By the way, the last commit can be easily edited with git commit --amend, try it out.

nnovich-OK
  • 2,900
  • 2
  • 13
  • 16
  • Ok, I think I understand it. So I'm supposed to get the SHA of the commit before the one that I actually want. Is that correct? – Alex Lowe Oct 30 '17 at 15:58
  • Yes. You can also specify it indirectly: both `5d8e041~1` and `5d8e041^` means "parent of 5d8e041", that would work too. – nnovich-OK Oct 30 '17 at 16:37
  • I also want to emphasize the same as noted in other answers. Rewriting local history (commit isn't yet pushed) is totally fine. Rewriting pushed commit (requires `--force`) is bad practice, brings lots of troubles if anyone has already pulled previous version. Pulling updated version will be really troublesome for them and might end up with total mess in repository on their next push. – nnovich-OK Oct 30 '17 at 16:56
  • When I ran `git rebase -i 5d8e041~1` I got `Current branch master is up to date.`. What do I do? It didn't even open the editor. – Alex Lowe Oct 30 '17 at 22:37
0

You need to select the hash of the parent commit, not the commit you want to change.

So if you have a git log that looks like this:
$ git log --oneline

5cd3b9a (HEAD -> master) Hi I'm John, I'm a bad commit message
b6266a5 Hi, I'm the parent of John
j45cj33 And I'm the grand parent of John
...

Rebase on the parent commit:

git rebase --interactive b6266a5

Then change the word pick to reword. When you save and exit a new editor will open up that allows you to change the commit message.

To update github you must use force. If your branch is called master, do this:

$ git push --force origin master

Keep in mind this will rewrite the history on github. If you rewrite the history after someone already pulled from github you will be asking for trouble.

BigHeadCreations
  • 1,583
  • 3
  • 16
  • 31
  • Yes: rebase, reword, force ushed. What I said. – VonC Oct 30 '17 at 06:02
  • I wish they had designed it so that one could edit a commit message without otherwise changing the history. – Andy Oct 30 '17 at 06:02
  • 1
    @BigHeadCreations But that's the issue, I can't even get to the point where I have the option to reword a commit. It just brings up the "blank" rebase that I put in my question. – Alex Lowe Oct 30 '17 at 11:57
  • @Alex Are you on the correct branch? Is the commit message you want to change the `head` of your current branch? If so you can also use `git commit --amend` like another answer mentioned. Or `git rebase -i HEAD~1` – BigHeadCreations Oct 30 '17 at 23:33
  • I'm on the correct branch. The commit message that I want to change is not at the head so I can't use `git commit - - amend`. – Alex Lowe Oct 31 '17 at 00:58
  • @Alex Are you typing the hash correctly? Run `git log --oneline`. All you need is the 7 digit hash that you see from that command. – BigHeadCreations Oct 31 '17 at 01:55
  • That's the exact command I ran and I copied the 7 digit correctly. Still no dice. – Alex Lowe Oct 31 '17 at 02:39
  • @Alex Do you get anything besides a "blank" rebase when you run `git rebase -i HEAD~1`? Just trying to troubleshoot. – BigHeadCreations Oct 31 '17 at 02:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157850/discussion-between-alex-and-bigheadcreations). – Alex Lowe Oct 31 '17 at 03:40