git 从分支中删除某些文件的提交历史记录
我已经开始开发一些小项目,并且没有使用功能分支。现在我想发布这个项目的一小部分,因为它足够稳定,可以发布。我想做的是:
创建一个“发布”分支,仅包含项目这部分的提交,并理想地从该分支的历史记录中完全删除其他部分。
有什么办法可以做到这一点吗?
更新
我想我忘记了一个重要信息:然后我想将发布分支推送到例如:github或其他一些开放托管平台。因此,我想删除已删除文件的历史记录。
非常感谢!
i've started development of some little project and did not use feature branches. now i would like to release a little part of this project, because it's stable enough to get released. what i would like to do is:
create a "release" branch with only the commits of this part of the project and ideally remove the other parts completly from the history of this branch.
is there any way to do this?
UPDATE
i think i forgot an important information: i would then like to push the release branch to e.g.: github or some other open hosting platform. because of this, i would like to have the history of the deleted files removed.
thanks very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从历史记录中删除文件意味着:
git filter-branch
(如“将子目录分离到单独的 Git 存储库" 和 "filter-branch --subdirectory-filter
更改 Git 存储库的 SHA1 。因此,如果您已经在 GitHub 上发布了存储库,则需要计划这样的操作(推送新历史记录),以便您的协作者能够将更改的历史记录考虑在内(如 从上游 REBASE 恢复 或
git rebase
手册页)。Removing files from the history means:
git filter-branch
(as in "Detach subdirectory into separate Git repository" and "how can I remove the unwanted objects from my repo afterfilter-branch --subdirectory-filter
")So if you have already published your repo on GitHub, such an operation (pushing a new history) needs to be planned in order for your collaborators to be able to take the changed history in to account (like in RECOVERING FROM UPSTREAM REBASE or the
git rebase
man page).您可以创建一个分支并删除随后不需要的每个文件。删除的文件在其他分支中仍然可用。
You can create a branch and remove every file which is unneeded afterwards. The removed files will be still available in the other branches.