在git中,我一直在提交到master分支,我真的应该在一个功能分支上工作.我想改变它,以便master回到它开始的地方,而master上的内容现在在一个新的分支上.基本上,我的提交历史记录如下:
A -- B -- C -- D -- E
| |
| master
origin/master
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
master
|
A -- B -- C -- D -- E
| |
| new_branch
origin/master
Run Code Online (Sandbox Code Playgroud)
如何更改主要点?
kni*_*ttl 70
git stashgit branch new_branchgit reset --hard origin/mastergit checkout new_branchgit stash pop如果您的工作树是干净的,则不需要使用stash/unstash.只需确保工作树中没有任何更改,因为重置时会删除这些更改--hard
另一种可能性(更快,无需存储和重置):
git checkout -b new_branch mastergit branch -f master origin/masterJ-D*_*zle 22
$ git checkout master
$ git reset --hard <commit-id-for-master-to-sit-at>
Run Code Online (Sandbox Code Playgroud)
例如试试这个
$ mkdir example; cd example
$ git init
$ vi testFile.txt
(now add "test commit 1" to line 1 of file)
$ git add *
$ git commit
(add message "(+) 1st commit" to git commit)
$ vi testFile.txt
(now add "test commit 2" to line 1 of file)
$ git add *
$ git commit
(add message "(+) 2nd commit" to git commit)
$ vi testFile.txt
(now add "test commit 3" to line 1 of file)
$ git add *
$ git commit
(add message "(+) 3rd commit" to git commit)
$ git tag final_head
$ git reset --hard HEAD~1
Run Code Online (Sandbox Code Playgroud)
此示例显示将主服务器移动到其他提交.请注意,标签允许我们保存旧主人,以防:)
| 归档时间: |
|
| 查看次数: |
32338 次 |
| 最近记录: |