In a project our git log was like
在一个项目中,我们的git日志就像
1--2--3----------------------------12-- (master)
\-4--5--------8---9------11-/ \ (branch1)
\--6-------/---10-/ \ (branch2)
\-7-------/ \ (branch3)
\-13 (newbranch)
and I want to have :
我希望:
1--2--3--4--5--6--7--8--9--10--11--12-- (master)
\-13 (newbranch)
That is to delete all branches but preserve the history and the commits (for further references).
这是删除所有分支但保留历史记录和提交(以供进一步参考)。
Thanks in advance.
提前致谢。
3
I would make this a comment but I don't have enough reputation yet. Can you clarify something - are commits 9 through 12 merge commits? If yes, why would you want to include merge commits in the linear history? Isn't the point of a linear history to omit merge commits?
我会对此作出评论,但我还没有足够的声誉。你能澄清一下 - 提交9到12次合并提交吗?如果是,为什么要在线性历史中包含合并提交?省略合并提交不是线性历史的重点吗?
Edit: Regardless, try this:
编辑:无论如何,试试这个:
1) Figure out the commit hash of commit 1. Let's say it's 5678.
1)弄清楚提交1的提交哈希值。假设它是5678。
2) git checkout master
. Then execute git rebase -i 5678
. You'll get a prompt. Reorder the commits 1 through 12. Then save and exit the editor.
2)git checkout master。然后执行git rebase -i 5678.你会得到一个提示。重新排序提交1到12.然后保存并退出编辑器。
3) git checkout newbranch
. Then execute git rebase master
.
3)git checkout newbranch。然后执行git rebase master。
Rewriting history is always risky, so I'd make sure to have another branch pointing to master before I tried this (origin/master or some other local branch), and that way if things go awry, I can git reset --hard <pointer-to-previous-master>
. Same goes for newbranch.
重写历史总是有风险的,所以我确保在我尝试这个之前有另一个分支指向master(origin / master或其他一些本地分支),这样如果出现问题,我可以git reset --hard <指针到先前的主> 。 newbranch也是如此。 指针到先前的主>
After you're done and everything looks good on master and newbranch, you can delete branches 1-3 using git branch -D
.
完成后,master和newbranch上的一切看起来都很好,你可以使用git branch -D删除分支1-3。
0
$ git checkout -b new/master 3 (3 should be replaced with the commit sha1 of 3)
$ git cherry-pick 4 (4 should be replaced with the commit sha1 of 4)
$ git cherry-pick 5
$ git cherry-pick 6
...
$ git cherry-pick 12
$ git checkout -b new/newbranch
$ git cherry-pick 13
$ git branch -D master
$ git branch -D branch1
$ git branch -D branch2
$ git branch -D branch3
$ git branch -D newbranch
$ git branch -m new/master master
$ git branch -m new/newbranch newbranch
0
I created a screencast answering this. Hope it'd help you.
我创建了一个回答这个的截屏视频。希望它对你有所帮助。
It demonstrates creating a straight Git tree based on a complex one, using SmartGit Git client.
它演示了如何使用SmartGit Git客户端创建基于复杂树的直接Git树。
https://www.youtube.com/watch?v=f-1u_MTr2Uw
https://www.youtube.com/watch?v=f-1u_MTr2Uw
0
You can check git log master
and git log newbranch
- that will looks exactly how you want. If you really want to remove all branches and merges and do history plain, it's better to use git rebase --root master
.
您可以检查git log master和git log newbranch - 这将完全符合您的要求。如果你真的想删除所有分支和合并并且历史记录是明确的,那么最好使用git rebase --root master。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2014/12/15/a1b42f217c3c4eea173eb86d3cafa23.html。