Git: move a commit “on top”

Let’s say in master I have a feature disabled.
I work on that feature on branch feature, so I have a special commit $ there that just enables that feature.
Now I want to merge the changes I did in feature into master, but keep the enabling commit out. So it’s like

main:    A--B--X--Y
feature: A--B--$--C--D

So let’s say I want to do it, by moving the $ commit on top of feature:

  • How to perform merge?
  • How does one work on a new git branch that depends on another git branch that is not yet merged?
  • Setting up a lab to experiment with GIT
  • Svn switch from trunk to branch
  • Why do I have to “git push --set-upstream origin <branch>”?
  • Git Merging Branch Into Master
  • new feature: A--B--C--D--$

    How would I go about doing that?

  • Is they a way to set push.default to `current` only for the current push
  • synchronizing files with server using git
  • Aptana 3.1.1 (17th April 2012) Doesn't track changes using Git
  • Azure git deploy of node project failing
  • Diff between Simulink models .slx
  • How can I create a gitsubtree of an existing repository?
  • 2 Solutions collect form web for “Git: move a commit “on top””

    git rebase -i B, and then move $ to the end of the list that shows up in your editor. It will start out as the first line in the file that opens. You could also just delete that line entirely, which will just drop that commit out of your branch’s history.

    If you want to keep you commits in the same order on feature you should make a new branch and perform the following. Otherwise just do this on feature

    git rebase -i <sha for commit B>

    Move commit $ to the bottom of the list

    git checkout master
    git rebase feature <or the other branch name>

    It wasn’t clear to me on the question but if you didn’t want $ at all, rather than moving it delete it after git rebase -i Though you will want to do this on a new branch so that you don’t lose it. As you are changing history.

    This also assumes that the branch feature hasn’t been pushed to a remote as rewriting history is bad.

    Git Baby is a git and github fan, let's start git clone.