diff --git a/additional-material/git_workflow_scenarios/resolving-merge-conflicts.md b/additional-material/git_workflow_scenarios/resolving-merge-conflicts.md index d749a92093ce3bd18f63715c32960f5ca25ebe3b..433ed24f50c35a4dbeb12701f33783175c744eec 100644 --- a/additional-material/git_workflow_scenarios/resolving-merge-conflicts.md +++ b/additional-material/git_workflow_scenarios/resolving-merge-conflicts.md @@ -33,3 +33,61 @@ You can also download different plugins depending on the IDE you are using for a # How to undo a merge? If you want to undo a merge then you can do `git merge —abort` + + +# Removed file merge conflicts +To resolve a merge conflict caused by competing changes to a file, where a person deletes a file in one branch and another person edits the same file, you must choose whether to delete or keep the removed file in a new commit. + +For example, if you edited a file, such as README.md, and another person removed the same file in another branch in the same Git repository, you'll get a merge conflict error when you try to merge these branches. You must resolve this merge conflict with a new commit before you can merge these branches. + +Open Terminal. + +Navigate into the local Git repository that has the merge conflict. + +``` +cd REPOSITORY-NAME +``` + +Generate a list of the files affected by the merge conflict. In this example, the file README.md has a merge conflict. +``` +$ git status +# On branch master +# Your branch and 'origin/master' have diverged, +# and have 1 and 2 different commits each, respectively. +# (use "git pull" to merge the remote branch into yours) +# You have unmerged paths. +# (fix conflicts and run "git commit") +# +# Unmerged paths: +# (use "git add/rm ..." as appropriate to mark resolution) +# +# deleted by us: README.md +# +# no changes added to commit (use "git add" and/or "git commit -a") +``` + +Open your favorite text editor, such as Atom, and navigate to the file that has merge conflicts. + +Decide if you want keep the removed file. You may want to view the latest changes made to the removed file in your text editor. + +To add the removed file back to your repository: +``` +$ git add README.md +``` + +To remove this file from your repository: +``` +$ git rm README.md +README.md: needs merge +rm 'README.md' +``` + +Commit your changes with a comment. +``` +$ git commit -m "Resolved merge conflict by keeping README.md file." +[branch-d 6f89e49] Merge branch 'branch-c' into branch-d +``` +You can now merge the branches on the command line + + +