git merge: Removing files I want to keep!

前端 未结 5 1354
别跟我提以往
别跟我提以往 2020-11-28 05:08

How can you merge two branches in git, retaining necessary files from a branch?

When merging two branches, if a file was deleted in one branch and not in an

5条回答
  •  醉梦人生
    2020-11-28 05:41

    My solution to this was to simply modify the files I needed to keep (added a comment which was needed anyway) and commit those changes on the target branch, thus generating a merge conflict which could easily be resolved with a git add and a normal commit.

    My history went something like this. Branch names have been changed to protect the innocent.

    1. create and commit files for a new feature to master
    2. realize this addition going to be more involved than originally planned, thus, branched to feature_branch
    3. Removed files from master so as not to disrupt normal workflow with RBs and such
    4. Time passes, more commits on master, none on feature_branch
    5. Resume work on the feature, git merge master on feature_branch causes original files to be removed (of course), git reset --hard to before the merge
    6. Applied the solution described above

提交回复
热议问题