Patrick Na
Patrick Na

Reputation: 119

Fix differences between two branches after git merge

I joined a project in which the master branch has not been touched for a while. The development happened on another branch without occasional merging. Now I would like to establish back the idea of having a master branch for stable code and the develop branch for ongoing work.

I therefore merged the develop branch and resolved conflicts, but noticed that a difference between the branches remained. Around 40 files exist in the develop branch that have not been taken into consideration by git merge. The explanation found in Differences between 2 branches after merge: GIT seems legit, but now my question:

How to resolve the difference and bring the missing files from the develop branch into the master branch?

Upvotes: 2

Views: 204

Answers (1)

Patrick Na
Patrick Na

Reputation: 119

Apparently this has been asked and answered already as part of a more extensive question. Here is the origin of the following, summarizing solution: Git Merge - Incomplete, Missing files and Folders

As described in the explanation link above, the missing files have been deleted in the master branch at some point. The way to bring them back is to restore those files from the log history.

Taken bits and pieces from the origin post this is what I did:

git checkout master
git diff developBranch --name-status |grep D > ~/deleted_files
git log --name-status > ~/file_history
cat ~/deleted_files | awk '{ print $2 }' | xargs -I haha git checkout developBranch haha
git commit -m 'Restore deleted files...'

Thanks to Quang Van, Walter Mundt and John Wu from the link above.

Upvotes: 1

Related Questions