git - 将文件从主目录移动到分支,然后从主目录中删除
问题描述
我有一个存储库,我在其中开始使用 Plotly 图表作为 Dash 应用程序的任务,然后在将 Dash 应用程序文件提交到 main 之后,决定暂时以完全不同的方式构建它。所以现在我有一堆与 Dash 应用程序相关的文件以及我实际需要的文件。我不想删除这些文件——我想稍后再回到那个方法——但如果我要在没有它们的情况下完成这个项目,我不希望它们出现在主分支中。
有没有办法从主分支中删除文件,但如果该分支当前不存在并且文件当前存在于主分支中,则将它们保留在不同的分支中?
解决方案
像这样尝试
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
祝你好运
推荐阅读
- regex - 简单的常规替换列表中的所有正则表达式
- ionic4 - 在离子加载控制器中显示加载项
- sql - 如何使用 SQL Developer 提供的“技巧”将每个表从特定用户转换为 JSON 格式
- javascript - js-cookie 的 Cookies.get 函数在重置后返回旧值
- python - 无法将 python 文件(包含硒)转换为 exe
- javascript - 如何在stimulus.js中获取元素的类
- node.js - 无法获取所有用户的列表
- c++ - 临时对象的复制构造函数调用
- ios - 通过 TabBarController 呈现 Modal ViewController
- docker - 如何为 swarm 容器启用 SYS_PTRACE