Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. Example: You have a branch `refactor` that is quite different from `master`. You can't merge all of the
  2. commits, or even every hunk in any single commit or master will break, but you have made a lot of
  3. improvements there that you would like to bring over to master.
  4.  
  5. _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._
  6.  
  7. On master:
  8.  
  9. > git checkout -b temp
  10.  
  11. On temp:
  12.  
  13. > git merge --no-commit --no-ff refactor
  14.  
  15. … which stages everything, so:
  16.  
  17. > git reset HEAD
  18.  
  19. Then begin adding the pieces you want:
  20.  
  21. > git add --interactive
  22.  
  23. *The following is from an actual merge.*
  24.  
  25. staged unstaged path
  26. 1: unchanged +1/-1 deploy_settings.py
  27. 2: unchanged +4/-3 requirements.txt
  28. 3: unchanged +2/-1 settings/defaults.py
  29. 4: unchanged +1/-1 settings/production.py.example
  30.  
  31. *** Commands ***
  32. 1: status 2: update 3: revert 4: add untracked
  33. 5: patch 6: diff 7: quit 8: help
  34. What now>
  35.  
  36. Choose `p` for patch.
  37.  
  38. staged unstaged path
  39. 1: unchanged +1/-1 deploy_settings.py
  40. 2: unchanged +4/-3 requirements.txt
  41. 3: unchanged +2/-1 settings/defaults.py
  42. 4: unchanged +1/-1 settings/production.py.example
  43. Patch update>>
  44.  
  45. 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.
  46.  
  47. When you are finished selecting files, press 'enter' without entering a number (or anything) to continue to the next step.
  48.  
  49. You will see a single diff hunk and it will ask you whether to stage it or not.
  50.  
  51. diff --git a/deploy_settings.py b/deploy_settings.py
  52. index 9b110f4..c5b228e 100644
  53. --- a/deploy_settings.py
  54. +++ b/deploy_settings.py
  55. @@ -4,7 +4,7 @@ This file holds the Fabric deployment settings for this project
  56. from fabric.state import env
  57.  
  58. #env.project = 'my_project' #The name of this project
  59. -#env.repo_base = 'git@git.oldsite.com:%s.git' % env.project
  60. +#env.repo_base = 'git@git.newsite.com:%s.git' % env.project
  61.  
  62. Stage this hunk [y,n,q,a,d,/,e,?]?
  63.  
  64. 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:
  65.  
  66. *** Commands ***
  67. 1: status 2: update 3: revert 4: add untracked
  68. 5: patch 6: diff 7: quit 8: help
  69. What now>
  70.  
  71. You can enter `s` to see what you changed
  72.  
  73. staged unstaged path
  74. 1: unchanged +1/-1 deploy_settings.py
  75. 2: +4/-3 nothing requirements.txt
  76. 3: +2/-1 nothing settings/defaults.py
  77. 4: unchanged +1/-1 settings/production.py.example
  78.  
  79. *** Commands ***
  80. 1: status 2: update 3: revert 4: add untracked
  81. 5: patch 6: diff 7: quit 8: help
  82. What now>
  83.  
  84. 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.
  85.  
  86. Don't forget to `git add` any untracked files as appropriate.
  87.  
  88. Commit the staged changes:
  89.  
  90. > git commit -m "merged selected patches from refactor branch"
  91. # don't do commit -a here… you only want to commit the staged changes
  92.  
  93. Revert the unstaged changes
  94.  
  95. > git checkout .
  96.  
  97. And finally, merge to master:
  98.  
  99. > git checkout master
  100. > git merge temp
  101. > git branch -D temp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement