是否可以用 git 中另一个目录中的冗余合并文件替换一个目录中的合并文件?

发布于 2025-01-10 20:52:31 字数 745 浏览 0 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2025-01-17 20:52:31

听起来你可以完全做你想做的事,而且不会有任何问题:

我试图减少冗余的方法是创建一个新分支,并用 Corrections_to_original_files_folder 的内容替换 original_folder 的内容,并从那里进行其他编辑.


我们假设您当前的重复文件夹结构如所述存在于 main 上。现在,让我们按照您所说的操作:

  1. 从主分支创建一个新分支:git switch -c new-branch main
  2. 文件夹Corrections_to_original_files_folder中的文件复制到original_folder >。 Git 会将这些文件显示为已全部编辑。
  3. 删除整个文件夹 Corrections_to_original_files_folder 。 Git 将继续显示其他文件夹的文件已编辑,并另外将所有这些文件显示为已删除。
  4. 使用措辞良好的提交消息来提交更改,解释您所做的事情以及原因。
  5. 像平常一样工作。

现在,如果您愿意,您可以将 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:

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.

Let's assume your current duplicate folder structure as described exists on main. Now let's do what you said:

  1. Make a new branch from main: git switch -c new-branch main
  2. Copy the files in folder corrections_to_original_files_folder into original_folder. Git will show those files as all edited.
  3. Delete the entire folder 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.
  4. Commit the change with a well worded commit message explaining what you did and why.
  5. Work as you normally would.

Now you can merge new-branch into main if you wish so that everyone can have the fix right away, or you can continue working on new-branch and merge it later. As soon as new-branch is merged into main 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文