git 将文件从main移动到分支,然后从main中删除

hl0ma9xz  于 2023-08-01  发布在  Git
关注(0)|答案(1)|浏览(144)

我有一个存储库,在那里我开始了一个任务,作为一个Dash应用程序与Plotly图表,然后决定建立一个完全不同的方式,现在,提交后的Dash应用程序文件的主要。所以现在我有一堆与达世币应用程序相关的文件沿着我实际需要的文件。我不想删除这些文件--我想稍后再回到这个方法--但是如果我打算在没有它们的情况下完成这个项目,我不希望它们出现在主分支中。
有没有一种方法可以从主分支中删除文件,但如果该分支当前不存在,而文件当前存在于主分支中,则将它们保留在不同的分支中?

7vux5j2d

7vux5j2d1#

尝试以下命令:

git checkout main-branch # just to be sure you are on main-branch
git checkout -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

字符串

相关问题