What to do if a merge deletes files you want to keep from your local repo #170
wrongkindofdoctor
started this conversation in
General
Replies: 1 comment
-
Great tips, @wrongkindofdoctor ! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A recent issue that a contributor had when merging the latest release prompted the following question: What should you if a merge deletes files that you want to keep?
In this scenario, all of the files in the directory for the POD developed on branch-B were deleted on branch-A, resulting in all of the POD files being deleted locally after checking out branch-B and running
git merge --no-ff branch-A
. To recover the files, there are a few options courtesy of Stack Overflow, two of which are shown below:git revert <merge commit hash>
. This will create a new commit for the revert.Once you've recovered your files, you can re-do the merge and retain the files on branch-B by performing minor modifications, such as adding a comment line. This is tedious if you have a lot of files, so it might be worth writing a script to insert dummy lines and run it on the desired directory(ies). Once the files are modified, add and commit them. For files in the same directory, you can use wildcards:
git add dir1/*.py
git add dir1/subdir1/*
Just check to make sure that there are no untracked files by running
git status
, then adding any leftovers to the staging area.After running
git commit
, re-do the merge:git merge --no-ff branch-A
You should get a message saying that there are merge conflicts, with the files that you modified marked as "deleted by them".
Add the files as you did before the merge to resolve the conflicts:
git add dir1/*...
Run
git status
to ensure that you have added all of the filesRun
git commit
to commit the merge. The Vim editor opens by default with a message summarizing the merge and conflict resolution.Enter
ESQ +wq
to write the message to the commit log and close the editorTest that the branch runs correctly
Push the changes on branch-B to your remote repository:
git push -u origin branch-B
Beta Was this translation helpful? Give feedback.
All reactions