0

Have looked around and can't find the answer to this! I am a complete git n00b and really grateful for anyone who can give me some pointers.

I initially had one long branch of commits in my repository and I wanted to change the message I had assigned to a previous commit (master~14) in the branch

So I did

git checkout master~14
git commit --amend -m "added the new description for the commit bla bla bla"

Unfortunately now I was placed into detached head mode So then I panicked a bit and created a new branch so that I wouldn't loose the ref to this commit

git branch detached

Now I have a situation like this, where I have master~14 at the top of the tree on its own branch, and I want to put it back where it was in the tree, without causing any conflicts or overwriting anything

+        [detached] xxxxx
  *    + [master] xxxxx
  *    + [master^] xxxxx
  *    + [master~2] xxxxx
  *    + [master~3] xxxxx
  *    + [master~4] xxxxx
  *    + [master~5] xxxxx
  *    + [master~6] xxxxx
  *    + [master~7] xxxxx
  *    + [master~8] xxxxx
  *    + [master~9] xxxxx
  *    + [master~10] xxxxx
  *    + [master~11] xxxxx
  *    + [master~12] xxxxx
  *    + [master~13] xxxxx
  *    + [master~14] xxxxx

I would also like (after this is resolved) to branch off my commits from master~14..master~5 as one new tree and finally master~4..master as another tree.

Imme22009
  • 3,992
  • 7
  • 31
  • 47
  • What I should have done to rename the commit message in the first place is answered here: http://stackoverflow.com/questions/179123/how-do-i-edit-an-incorrect-commit-message-in-git – Imme22009 Jul 24 '12 at 16:24

2 Answers2

1

q1:

git checkout master

This would return you back to the master tip

or use

git reflog

or git reflog show master

to see how the pointers were moving

But better approach to the whole stuff would be

git rebase -i master~14

then mark the necessary commit to stop for amending, then you wouldn't be in detached HEAD state

q2: To me it sounds like you want master~14..master~5 and master~4..master to start from master~15 if that's correct (i will create named branches for simplicity):

git branch feature1 master~5
git branch master15back master~15
git rebase --onto master15back feature1 master

see git rebase doc

Eugene Sajine
  • 8,104
  • 3
  • 23
  • 28
  • Thanks for the help. For (a) What I actually ended up doing was: git branch -D detached Then I re-did the rename following the advice here: http://stackoverflow.com/questions/179123/how-do-i-edit-an-incorrect-commit-message-in-git – Imme22009 Jul 24 '12 at 16:30
0

For q1, you can try git rebase -i master~14

After this, change the relate commit to r means update the commit message

Tim
  • 2,006
  • 2
  • 18
  • 25