开发者

Git: Move a few of the last commits to a new branch and then create a patch for them

I've made a few commits and now I want them (say from some commit in the branch) to move them into a new branch, i.e.:

 master - O1-O2-O3-X-C1-C2-C3 

to become

master - O1-O2-O3-X  
                   \ new_branch - C1-C2-C3

After that I need to make patches for the mentioned commits (C1, C2, C3) so that a friend of mine would be able to apply them on their tree.

As to the first part I suppose I should do something like:

  1. Create patches for x -> C3
  2. Reset to X
  3. 开发者_如何学Python
  4. Create branch
  5. Apply patches

Although here they suggest that I could use git branch new_branch; git reset --hard X; git checkout new_branch. Wouldn't reset --hard delete my commits?

I'm not too good with git to do it all without guidance. Thanks!


No reset --hard wouldn't delete your commits, as they would still be referenced by the 'new_branch' branch.
(meaning that, by a checkout of 'new_branch', you would recover and see those commits again)

But it would delete any untracked changed in your working tree though, so make sure you don't have any work in progress before typing that command.

You can see a more detailed illustration of that sequence of commands in "What will git checkout master + git reset --hard do?".


To complete Stuart Golodetz's comment, should a git reset had removed or erased any commit, you would still have been able to get hold of those commit with a git reflog.
See:

  • "Undoing a git rebase"
  • "Undoing a git reset --hard HEAD~1"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜