如何推动没有历史的新分支 [英] How to push new branch without history

查看:90
本文介绍了如何推动没有历史的新分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不相关的分支,master和config的git repo。
我已经创建了配置文件,清除了所有文件,然后仅放置在配置文件中。
现在我想在远程repo上推送它,但是因为它是新的,空的分支(没有我的所有更改的日志以及原始分支的旧版本)。



如何清除所有历史记录并推送它? 清除所有文件不会清除历史记录。您需要先创建一个没有历史记录的分支,然后添加您的配置文件。这几天 git checkout 有一个 - orphan 选项,它使得没有历史记录的分支。以下是关于 - orphan 选项的信息:​​


- 孤儿 new_branch>



创建一个名为< new_branch的新的孤立分支,从< start_point>开始并切换到它。在这个新分支上做的第一次提交将没有父母,它将成为与所有其他分支和提交完全断开连接的新历史记录的根。



索引和调整工作树,就好像您之前运行过git checkout< start_point>一样。这允许您通过轻松运行git commit -a来创建一个新的历史记录来记录一组类似于< start_point>的路径,以便进行根提交。



如果您想从提交中发布树而不公开完整的历史记录,这会很有用。您可能想要这样做来发布项目的开源分支,该分支的当前树是干净的,但其完整历史记录包含专有或以其他方式设计的代码位。



如果你想开始一个断开的历史记录,记录一组完全不同于< start_point>的路径,那么你应该在创建孤立分支后立即清除索引和工作树,方法是运行git rm - rf。来自工作树的顶层。之后,您将准备好准备新文件,重新填充工作树,从别处复制它们,提取tarball等。


以下是结帐的文档链接。您也可以运行 git help checkout



创建没有历史记录的分支后,你把它推到服务器上,它也不会有这个历史。 FWIW,它帮助我将 git push 看作使远程分支看起来与我的本地分支相同。所以如果你有历史,推动,它会有历史。如果你不这样做,那么推送的分支将不会。


I have git repo with two unrelated branches, master and configs. I've created configs, purged all the files and then placed in configuration files only. Now I want to push this on remote repo, but as it were new, empty branch (without logs of all my changes and old revisions of original branch).

How can I purge all the history and push it?

解决方案

Purging all the files doesn't get rid of the history. You need to create a branch that has no history first, and the add your config files. These days git checkout has a --orphan option that makes a branch with no history. Here's the information on the --orphan option:

--orphan <new_branch>

Create a new orphan branch, named <new_branch>, started from <start_point> and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.

The index and the working tree are adjusted as if you had previously run "git checkout <start_point>". This allows you to start a new history that records a set of paths similar to <start_point> by easily running "git commit -a" to make the root commit.

This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.

If you want to start a disconnected history that records a set of paths that is totally different from the one of <start_point>, then you should clear the index and the working tree right after creating the orphan branch by running "git rm -rf ." from the top level of the working tree. Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.

Here's a link to the documentation for checkout. You can also run git help checkout as well.

Once you've created your branch without history, then when you push it to the server, it won't have that history either. FWIW, it helps me to think of git push as "make the remote branch look the same as my local one". So if you have history, and push, it will have history. If you don't, then the pushed branch won't.

这篇关于如何推动没有历史的新分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆