Git rebase since the last merge operation

Let’s consider this situation where I work on a particular feature on separate branch:

* 456789 bar (origin/master, origin/HEAD, master)
| * 3456789 foo (HEAD -> feature)
| *   2345678 Merge origin/master in feature
| |\
| |/
* | 1234567 

Some time ago I merged the master, but since then I did foo on my feature while somebody did bar on the master.

  • Git push problems
  • Git undo alias not working properly
  • How to develop PHP packages in a team using composer?
  • How to handle elastic beanstalk deployment so it uploads only changed files
  • Multi-Device Hybrid Apps installation error
  • Learning about version control systems, Git, SVN
  • Now, I would like to rebase bar right before my last merge:

    * 3456789 foo (HEAD -> feature)
    * 2345678 Merge origin/master in feature
    | |  
    | |
    * | 456789 bar (origin/master, origin/HEAD, master) 

    I tried a git rebase master from feature. The problem is that Git wants to replay all my changes on the top of the master which can be a lot of work.

    One possible solution would be this:

    $ git checkout -b temp feature~3
    $ git merge master
    $ git cherry-pick foo -n2
    $ git branch -D feature
    $ git branch -m temp feature
    $ git checkout feature
    $ git branch -D temp

    I am sure there is an easier way to do it.

  • git create branch with existing local commits
  • Images corrupt after git push
  • how to know which commit was last checked out?
  • Create a branch in a repo without cloning
  • Can't clone eclipse project into workspace
  • The proper way to “merge” this situation
  • One Solution collect form web for “Git rebase since the last merge operation”

    What you described at the end of your question is a good way to do it.

    Here you can figure and understand what is going on.
    How to move HEAD back to a previous location? (Detached head)

    Another option is to do a sqaush

    As squash is an interactive rebase which allow you to modify any commit you wish in any way. Using the edit command you can edit and add any commits at any given point of the history.

    In order to do a git squash follow those steps:

    // X is the number of commits you wish to squash, in your case 6
    git rebase -i HEAD~X

    Once you squash your commits – choose the e for edit and the manipulate the desired commits.

    If you wish to keep the commit as is so you should use what you have suggested with the git cherry-pick

    enter image description here

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