简体   繁体   中英

Git rebase interactive - how to rebase only this branch commits?

I have a local branch let's call it DEV. The branch commits history looks like this:

module_A: add CRC verification (9273467932)

module_B: change shutdown procedure (84705723)

Merge pull request #918 from XXX (265424)

module_D: cleanup (3859236)

Merge branch fix_for_drain_issue (38572693)

(...)

Now, I don't like the fourth commit message "cleanup" it is to vague so I would like to edit it. So I go:

git rebase -i 3859236

vim opens up and I mark 3859236 as edit . Next I do git commit --ammend and change the commit message to sth more descriptive. So far so good. Since that was the only change I wanted to make I finally issue git rebase --continue And here surprise:

interactive rebase in progress: (...) both modified: tools/src/file.c How is that possible? All I have done was just the change of commit message right? So how in the world git raises a conflicting files? My theory is that git tries to rebase all commits from the merged commits I have and this may cause conflicts. Especially if in the meantime I have pulled these branches.

I have tried everything already -p to preserve commit messages; -r to recreating the merge commits - no success, it always tried to rebase these branches. I also see it when rebase edit-todo list shows up. It list commits which are not on my current branch but are on these branches from which I merged or cherry picked.

So my question boils down to this - How can I limit the rebase to only reorganize commits from this particular branch. Or alternatively how to edit, sometimes squash commits in this branch without rebasing.

You don't want to edit the revision.... you want to reword it.

# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.

And you end up with a message like that because you are committing behind rebase's back. If you want to use edit, when the revision stops, you add your changes to the index and then you run git rebase --continue , you don't get to commit on your own... if you choose to use reword , once you save the content of the file on the editor, when you exit from it, rebase will automatically continue, no need to ask it to continue.

Try the same process, but with a rebase -i using the commit before the one you want to edit.

That will replay your edit on top of an existing commit (the one before)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM