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?
CodePudding user response:
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 ofcorrections_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:
- Make a new branch from main:
git switch -c new-branch main
- Copy the files in folder
corrections_to_original_files_folder
intooriginal_folder
. Git will show those files as all edited. - 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. - Commit the change with a well worded commit message explaining what you did and why.
- 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.