0

Context:

I'm learning how to use git with Eclipse and am using it for a small project with only a local repository.

Problem:

  • I just noticed that a commit I made earlier has an incorrect description attached to it.
  • There's nothing wrong with the files I committed or anything but for clarity's sake (if I want to revert or whatever) I'd like to change the description which is misleading.
  • I can't just amend previous commit as I have made more commits since then.

Floundering attempts to solve problem:

I variously tried creating new branches, amending commits and then rebasing, but end up with a bunch of scary looking merge conflicts and a spaghetti looking history tree. I could just copy and paste my newer commits into txt files, revert back to the commit with the wrong info and start again from there, but I figure the whole point of using git is to avoid doing stuff like that.

Question:

Is there a simple way to just change an older commit's description text?

If not what are the steps for the complicated way in egit?!

Community
  • 1
  • 1
mallardz
  • 1,070
  • 11
  • 21

1 Answers1

2

If you already pushed the revisions somewhere: don't!

Otherwise: use git rebase -i <SOME_OLD_REVISION> and mark the commits to be changed with the r(eword) option.

Once you close the file that was popped up, rebasing will start and you'll be prompted for every commit you chose to enter the new commit message.

Assume you have the following commit history (newest first):

f6f6f6f last commit
d4d4d4d ...
c3c3c3c third commit
b2b2b2b second commit
a1a1a1a first commit

And want to change the messages for b2b2b2b and c3c3c3c, you would do

git rebase -i a1a1a1a

Next, your favourite editor will pop up and show you this dialog:

pick f6f6f6f last commit
pick ...
pick c3c3c3c third commit
pick b2b2b2b second commit

# Rebase b2b2b2b..f6f6f6f onto a1a1a1a
#
# 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
#
# 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

Change pick to r or reword for commits b2b2b2b and c3c3c3c, save the file and exit the editor.

Next, rebasing will start.

For the commits you chose to reword, you could then enter the new commit message.

eckes
  • 64,417
  • 29
  • 168
  • 201
  • +1 for a comprehensive looking answer, but I was hoping for an answer for egit, the eclipse plugin. I've yet to use git at the shell level (guess I should learn.) I'm only using local repository, so nowhere to push to. – mallardz May 26 '14 at 12:17
  • 1
    @mallardz: see http://stackoverflow.com/q/7197152/520162 for rebase -i on egit. Maybe this helps. – eckes May 26 '14 at 16:20
  • Ok turns out egit has got an interactive rebase window that you can use in the Git perspective. I was just about able to muddle through. I've also started learning the git basics at bash level and it's proving very helpful so +1 for getting me to do that as well. – mallardz Jun 16 '14 at 17:20