首页 > 解决方案 > 将文件从主目录移动到分支,然后从主目录中删除

问题描述

我有一个存储库,我在其中开始使用 Plotly 图表作为 Dash 应用程序的任务,然后在将 Dash 应用程序文件提交到 main 之后,决定暂时以完全不同的方式构建它。所以现在我有一堆与 Dash 应用程序相关的文件以及我实际需要的文件。我不想删除这些文件——我想稍后再回到那个方法——但如果我要在没有它们的情况下完成这个项目,我不希望它们出现在主分支中。

有没有办法从主分支中删除文件,但如果该分支当前不存在并且文件当前存在于主分支中,则将它们保留在不同的分支中?

标签: git

解决方案


像这样尝试

git checkout main-branch # just to be sure you are on main-branch
git chekcout -b main-branch-backup # now you have all commits (like a copy) from main-branch here
git log # verify in the commit log history, all commits will be here
git checkout main-branch # move back to main-branch

git checkout -b test-removing # like main-branch-backup but here you remove things
# assume you need to remove the last two commits you can do like so or change the number from the next line
git reset --hard HEAD~2 

# if it worked you can do the same on main-branch, if it did not work
# as you expected, remove the branch test-removing and start again

祝你好运


推荐阅读