是否可以用 git 中另一个目录中的冗余合并文件替换一个目录中的合并文件?
我对 Git 还很陌生,但是我正在尝试纠正我之前创建的一些非常的文件结构,但不确定如何纠正。
本质上我们拥有的是这样的结构:
--original_folder
-- file1
-- file2
-- file3
-- file4
-- file5
--corrections_to_original_files_folder
-- file1
-- file2
-- file3
-- file4
-- file5
original_folder
代表第一个合并分支,Corrections_to_original_files_folder
代表第二个合并分支(您猜对了,它包含对这些文件的更正)。
显然,这是一种非常糟糕的方法。我试图减少冗余的方法是创建一个新分支,并用 Corrections_to_original_files_folder 的内容替换
original_folder
的内容,并从那里进行其他编辑。
但是,我尝试了几种方法,因为此代码全部合并,所以我不能依赖任何 git mv 方法或 git checkout origin/BRANCH_TO_MOVE_FROMdesired_file.py 。
谁能帮我解决这个垃圾箱火灾吗?
I am still fairly new to Git, however I am trying to correct some of the very poor file structure I created previously and am unsure how.
Essentially what we have is this structure:
--original_folder
-- file1
-- file2
-- file3
-- file4
-- file5
--corrections_to_original_files_folder
-- file1
-- file2
-- file3
-- file4
-- file5
original_folder
represents the first merged branch, and corrections_to_original_files_folder
represents the second merged branch (which, you guessed it, contains corrections to those files).
Obviously this was a really POOR way to do this. What I am trying to do to reduce redundancy is create a new branch, and essentially replace the contents of original_folder
with the contents of corrections_to_original_files_folder
and from there making additional edits.
I have tried several methods however, because this code is all merged, I cannot rely on any of the git mv
methods, OR the git checkout origin/BRANCH_TO_MOVE_FROM desired_file.py
.
Can anyone help me fix this dumpster fire?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来你可以完全做你想做的事,而且不会有任何问题:
我们假设您当前的重复文件夹结构如所述存在于
main
上。现在,让我们按照您所说的操作:git switch -c new-branch main
将Corrections_to_original_files_folder
中的文件复制到original_folder
>。 Git 会将这些文件显示为已全部编辑。Corrections_to_original_files_folder 。 Git 将继续显示其他文件夹的文件已编辑,并另外将所有这些文件显示为已删除。
现在,如果您愿意,您可以将
new-branch
合并到main
中,以便每个人都可以立即修复,或者您可以继续处理new-branch
code> 并稍后合并它。一旦new-branch
合并到main
中,“修复”就会被应用。请注意,这几乎正是您所说的您想做的事情。我猜你只是没有意识到它会起作用,但它应该起作用。
It sounds like you can do exactly what you want to do, and you won't have any issues with it:
Let's assume your current duplicate folder structure as described exists on
main
. Now let's do what you said:git switch -c new-branch main
corrections_to_original_files_folder
intooriginal_folder
. Git will show those files as all edited.corrections_to_original_files_folder
. Git will continue to show the other folder's files as edited, and additionally show all of these files as deleted.Now you can merge
new-branch
intomain
if you wish so that everyone can have the fix right away, or you can continue working onnew-branch
and merge it later. As soon asnew-branch
is merged intomain
the "fix" will be applied.Note this is pretty much exactly what you said you wanted to do. I'm guessing you just didn't realize that it would work, but it should.