Skip to content

Instantly share code, notes, and snippets.

@Martin288
Forked from katylava/git-selective-merge.md
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save Martin288/121fa0018a5c0b0a540a to your computer and use it in GitHub Desktop.

Select an option

Save Martin288/121fa0018a5c0b0a540a to your computer and use it in GitHub Desktop.

Revisions

  1. @katylava katylava revised this gist Jan 7, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git-selective-merge.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@ Example: You have a branch `refactor` that is quite different from `master`. You
    commits, or even every hunk in any single commit or master will break, but you have made a lot of
    improvements there that you would like to bring over to master.

    _Note: This will not preserve the original change authors. Only use if necessary, or if you don't mind losing that information, or if you are only merging your own work._

    On master:

    > git co -b temp
  2. katy lavallee revised this gist Jul 25, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-selective-merge.md
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ You can enter `s` to see what you changed

    You can quit now, so enter `q`, Then do some status and diff commands to explore the staged vs unstaged changes and make sure it looks like you expected.

    Don't forget to `git add` or `git rm` any untracked files as appropriate.
    Don't forget to `git add` any untracked files as appropriate.

    Commit the staged changes:

  3. katy lavallee revised this gist Jul 25, 2012. 2 changed files with 99 additions and 100 deletions.
    100 changes: 0 additions & 100 deletions git selective merge
    Original file line number Diff line number Diff line change
    @@ -1,100 +0,0 @@
    Example: You have a branch 'refactor' that is quite different from master. You can't merge all of the
    commits, or even every hunk in any single commit or master will break, but you have made a lot of
    improvements there that you would like to bring over to master.

    # on master
    > git co -b temp

    # on temp
    > git merge --no-commit --no-ff refactor

    # … which stages everything, so...
    > git reset head
    > git add --interactive

    # The following is from an actual merge.

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: unchanged +4/-3 requirements.txt
    3: unchanged +2/-1 settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    # choose 'p' for patch.

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: unchanged +4/-3 requirements.txt
    3: unchanged +2/-1 settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example
    Patch update>>

    # enter the number next to the file you want to process first.

    # you can keep entering numbers until you've selected all the files,
    # or you can do them one at a time. an asterisk will appear next to
    # the files you select.

    # press 'enter' without entering a number (or anything) to continue
    # to the next step.

    # you will see a single diff hunk and it will ask you whether to stage
    # it or not

    diff --git a/deploy_settings.py b/deploy_settings.py
    index 9b110f4..c5b228e 100644
    --- a/deploy_settings.py
    +++ b/deploy_settings.py
    @@ -4,7 +4,7 @@ This file holds the Fabric deployment settings for this project
    from fabric.state import env

    #env.project = 'my_project' #The name of this project
    -#env.repo_base = 'git@git.oldsite.com:%s.git' % env.project
    +#env.repo_base = 'git@git.newsite.com:%s.git' % env.project

    Stage this hunk [y,n,q,a,d,/,e,?]?

    # y for yes, n for no
    # … this will go on for every diff hunk in the selected files
    # … until you get back to …

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    # you can enter 's' to see what you changed

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: +4/-3 nothing requirements.txt
    3: +2/-1 nothing settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    # you can quit now, so enter 'q'
    # then do some status and diff commands to explore the staged vs unstaged
    # changes and make sure it looks like you expected.

    # don't forget to git add or just rm any untracked files as appropriate
    # finally…

    > git commit -m "merged selected patches from refactor branch"
    # don't do commit -a here… you only want to commit the staged changes

    # revert unstaged changes
    > git co .

    # and merge to master
    > git co master
    > git merge temp
    > git br -D temp
    99 changes: 99 additions & 0 deletions git-selective-merge.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    Example: You have a branch `refactor` that is quite different from `master`. You can't merge all of the
    commits, or even every hunk in any single commit or master will break, but you have made a lot of
    improvements there that you would like to bring over to master.

    On master:

    > git co -b temp

    On temp:

    > git merge --no-commit --no-ff refactor

    … which stages everything, so:

    > git reset head

    Then begin adding the pieces you want:

    > git add --interactive

    *The following is from an actual merge.*

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: unchanged +4/-3 requirements.txt
    3: unchanged +2/-1 settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    Choose `p` for patch.

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: unchanged +4/-3 requirements.txt
    3: unchanged +2/-1 settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example
    Patch update>>

    Enter the number next to the file you want to process first. You can keep entering numbers until you've selected all the files, or you can do them one at a time. An asterisk will appear next to the files you select.

    When you are finished selecting files, press 'enter' without entering a number (or anything) to continue to the next step.

    You will see a single diff hunk and it will ask you whether to stage it or not.

    diff --git a/deploy_settings.py b/deploy_settings.py
    index 9b110f4..c5b228e 100644
    --- a/deploy_settings.py
    +++ b/deploy_settings.py
    @@ -4,7 +4,7 @@ This file holds the Fabric deployment settings for this project
    from fabric.state import env

    #env.project = 'my_project' #The name of this project
    -#env.repo_base = 'git@git.oldsite.com:%s.git' % env.project
    +#env.repo_base = 'git@git.newsite.com:%s.git' % env.project

    Stage this hunk [y,n,q,a,d,/,e,?]?

    Enter `y` to stage or `n` to skip. This will go on for every diff hunk in the selected files until you get back to:

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    You can enter `s` to see what you changed

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: +4/-3 nothing requirements.txt
    3: +2/-1 nothing settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    You can quit now, so enter `q`, Then do some status and diff commands to explore the staged vs unstaged changes and make sure it looks like you expected.

    Don't forget to `git add` or `git rm` any untracked files as appropriate.

    Commit the staged changes:

    > git commit -m "merged selected patches from refactor branch"
    # don't do commit -a here… you only want to commit the staged changes

    Revert the unstaged changes

    > git checkout .

    And finally, merge to master:

    > git checkout master
    > git merge temp
    > git branch -D temp
  4. @katylava katylava revised this gist Sep 3, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git selective merge
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ index 9b110f4..c5b228e 100644

    #env.project = 'my_project' #The name of this project
    -#env.repo_base = 'git@git.oldsite.com:%s.git' % env.project
    +#env.repo_base = 'git@git.newsite.com:%s.git' % env.project #The base svn repository for this project (ie, parent of trunk)
    +#env.repo_base = 'git@git.newsite.com:%s.git' % env.project

    Stage this hunk [y,n,q,a,d,/,e,?]?

  5. @katylava katylava revised this gist Sep 3, 2010. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions git selective merge
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,18 @@
    Example: You have a branch 'refactor' that is quite different from master. You can't merge all of the
    commits, or even every hunk in any single commit or master will break, but you have made a lot of
    commits, or even every hunk in any single commit or master will break, but you have made a lot of
    improvements there that you would like to bring over to master.

    # on master
    > git co -b temp

    # on temp
    > git merge --no-commit --no-ff refactor

    # … which stages everything, so...
    > git reset head
    > git add --interactive

    The following is from an actual merge.
    # The following is from an actual merge.

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    @@ -54,9 +56,7 @@ index 9b110f4..c5b228e 100644
    #env.project = 'my_project' #The name of this project
    -#env.repo_base = 'git@git.oldsite.com:%s.git' % env.project
    +#env.repo_base = 'git@git.newsite.com:%s.git' % env.project #The base svn repository for this project (ie, parent of trunk)

    ## Directory aliases ##
    # These are used in the apache vhost config file to defined directory aliases.

    Stage this hunk [y,n,q,a,d,/,e,?]?

    # y for yes, n for no
  6. @katylava katylava revised this gist Sep 3, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git selective merge
    Original file line number Diff line number Diff line change
    @@ -52,8 +52,8 @@ index 9b110f4..c5b228e 100644
    from fabric.state import env

    #env.project = 'my_project' #The name of this project
    -#env.repo_base = 'git@thomasjefferson.katylavallee.com:%s.git' % env.project
    +#env.repo_base = 'git@git.farstarserver.com:%s.git' % env.project #The base svn repository for this project (ie, parent of trunk)
    -#env.repo_base = 'git@git.oldsite.com:%s.git' % env.project
    +#env.repo_base = 'git@git.newsite.com:%s.git' % env.project #The base svn repository for this project (ie, parent of trunk)

    ## Directory aliases ##
    # These are used in the apache vhost config file to defined directory aliases.
  7. @katylava katylava revised this gist Sep 3, 2010. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion git selective merge
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    Example: You have a branch 'refactor' that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.
    Example: You have a branch 'refactor' that is quite different from master. You can't merge all of the
    commits, or even every hunk in any single commit or master will break, but you have made a lot of
    improvements there that you would like to bring over to master.

    # on master
    > git co -b temp
  8. @katylava katylava renamed this gist Sep 3, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @katylava katylava created this gist Sep 3, 2010.
    98 changes: 98 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,98 @@
    Example: You have a branch 'refactor' that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.
    # on master
    > git co -b temp
    # on temp
    > git merge --no-commit --no-ff refactor
    # … which stages everything, so...
    > git reset head
    > git add --interactive
    The following is from an actual merge.
    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: unchanged +4/-3 requirements.txt
    3: unchanged +2/-1 settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example
    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>
    # choose 'p' for patch.
    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: unchanged +4/-3 requirements.txt
    3: unchanged +2/-1 settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example
    Patch update>>
    # enter the number next to the file you want to process first.
    # you can keep entering numbers until you've selected all the files,
    # or you can do them one at a time. an asterisk will appear next to
    # the files you select.

    # press 'enter' without entering a number (or anything) to continue
    # to the next step.

    # you will see a single diff hunk and it will ask you whether to stage
    # it or not

    diff --git a/deploy_settings.py b/deploy_settings.py
    index 9b110f4..c5b228e 100644
    --- a/deploy_settings.py
    +++ b/deploy_settings.py
    @@ -4,7 +4,7 @@ This file holds the Fabric deployment settings for this project
    from fabric.state import env

    #env.project = 'my_project' #The name of this project
    -#env.repo_base = 'git@thomasjefferson.katylavallee.com:%s.git' % env.project
    +#env.repo_base = 'git@git.farstarserver.com:%s.git' % env.project #The base svn repository for this project (ie, parent of trunk)

    ## Directory aliases ##
    # These are used in the apache vhost config file to defined directory aliases.
    Stage this hunk [y,n,q,a,d,/,e,?]?

    # y for yes, n for no
    # … this will go on for every diff hunk in the selected files
    # … until you get back to …

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    # you can enter 's' to see what you changed

    staged unstaged path
    1: unchanged +1/-1 deploy_settings.py
    2: +4/-3 nothing requirements.txt
    3: +2/-1 nothing settings/defaults.py
    4: unchanged +1/-1 settings/production.py.example

    *** Commands ***
    1: status 2: update 3: revert 4: add untracked
    5: patch 6: diff 7: quit 8: help
    What now>

    # you can quit now, so enter 'q'
    # then do some status and diff commands to explore the staged vs unstaged
    # changes and make sure it looks like you expected.

    # don't forget to git add or just rm any untracked files as appropriate
    # finally…

    > git commit -m "merged selected patches from refactor branch"
    # don't do commit -a here… you only want to commit the staged changes

    # revert unstaged changes
    > git co .

    # and merge to master
    > git co master
    > git merge temp
    > git br -D temp