gpt4 book ai didi

git - 如何在没有历史记录的情况下推送新分支

转载 作者:IT王子 更新时间:2023-10-29 00:34:26 25 4
gpt4 key购买 nike

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

如何清除所有历史记录并推送它?

最佳答案

清除所有文件并不能消除历史记录。您需要先创建一个没有历史记录的分支,然后添加您的配置文件。现在 git checkout 有一个 --orphan 选项,可以创建一个没有历史记录的分支。以下是有关 --orphan 选项的信息:​​

--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.

这是 checkout 文档的链接.您也可以运行 git help checkout

一旦您创建了没有历史记录的分支,那么当您将它推送到服务器时,它也不会有该历史记录。 FWIW,它帮助我将 git push 视为“使远程分支看起来与本地分支相同”。所以如果你有历史,然后 push ,它就会有历史。如果不这样做,则推送的分支不会。

关于git - 如何在没有历史记录的情况下推送新分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12543055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com