Pregunta

In GitI have following situation:

o "ok" b6ca869   [my_branch*]
|
o "ok" 479d27c
|
o "ok" c80fad5
|
o "ok" 8f7fe87
|
o "master commit message" [master][remotes/origin/master]

I want to squeeze those 4 "ok" commits to and furthermore change the message

o "my_branch commit message"    [my_branch*]
|
o "master commit message" [master][remotes/origin/master]

So what I do is

git rebase --interactive master

And GNU nano (I'm on Ubuntu) editor is opened

GNU nano 2.2.2             File: /home/.git/modules/src/android/frameworks/base/rebase-merge/git-rebase-todo                                

pick 8f7fe87 ok
pick c80fad5 ok
pick 479d27c ok
pick b6ca869 ok

# Rebase aeedb8f..b6ca869 onto aeedb8f
#
# 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

As I understand I have to edit this file, but actually I don't know how.

¿Fue útil?

Solución

You need to squash the last 3 commits to the first one so(s stands for squash):

pick 8f7fe87 ok
s c80fad5 ok
s 479d27c ok
s b6ca869 ok

Save and then exit, and a new buffer should popup with all the commit messages. Simply use/modify the commit that you want to have at the end, save and exit.

Otros consejos

you can squash together the last 4 commits; since you committed them locally. To do that you would edit the file to:

pick 8f7fe87 ok
s c80fad5 ok
s 479d27c ok
s b6ca869 ok

after that you will be able to change the (combined) commit message.

However this will not squash them on the last commit with "master commit message". The problem is that your "master commit" has been pushed to the server; so you cannot simply append commits to a commit that has been pushed to the server.

That commit has a certain "hash" code; and since other users might have pulled that code; git does not (or not easily) allow to append to a commit that has already been pushed to the server. If you want to do that, you can see this question

Change the three lower picks to squash, then save and exit. Another editor will pop up, allowing you to change the commit message.

If you want to undo the rebase for any reason, have a look at git reflog. It will show you the sha1 of the state before the rebase, and you can return to that state by doing a git reset --hard sha1. There also is a shortcut to reference the reflog, git reset --hard @{1}

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top