简体   繁体   中英

How do I undo a git pull from another branch and resolve merge conflict?

In Visual Studio 2019, I was working on my local repository branch named "feature/ABC-subpage-edits" that was pulled from the remote repository "master" branch with latest changes. I made changes to at least 4 files (let's call them, subpage1.html, subpage2.html, subpage3.html, subpage4.html). After I committed, staged and push my changes to BitBucket and made a pull request for approval to "Development" branch (QA site)...subpage3.html gave a merge conflict that needs to be resolved.

Bitbucket gave the following warning: This pull request can't be merged. You will need to resolve conflicts to be able to merge. More information.

I clicked on "More information" and told me to do:

Step 1: Checkout the source branch and merge in the changes from the target branch. Resolve conflicts.

git checkout feature/ABC-subpage-edits
git pull origin Development

Step 2: After the merge conflicts are resolved, stage the changes accordingly, commit the changes and push.

git commit
git push origin HEAD

Step 3: Merge the updated pull request.

I did do:

git checkout feature/ABC-subpage-edits
git pull origin Development

I went into the file "subpage3.html" to fix the merge conflict by using the Merge Conflict Editor in Visual Studio 2019 and I clicked Accept Merge to finalize the changes.

But the issue is that when I did a "git pull origin Development", it put a whole bunch of other modified files into my local repo as Staged Changes which I didn't make but other developers made and were still working on from "Development" branch are now in my local repo branch "feature/ABC-subpage-edits".

I was wondering how do I undo the "git pull origin Development" command and return my local repo branch to the state it was before with just my changes only? Is there a way to backtrack that change?

How do I properly fix a merge conflict in "subpage3.html" without pulling from the Development branch that pulls all the other changes too and just fix the one file that has the conflict and commit just that change to the pull request instead?

git reset is your friend with

git reset --keep HEAD@{1}

If I understood you right, depending on how you handle things, I see two options:

  1. I would suggest you to checkout Development clean first. Then apply your changes to the feature/ABC-subpage-edits by merging or rebasing.
  2. Since you branched off of master , you should merge it back into master . And then apply new changes to a separate branch.
master -- Development
   |
   |----- feature/ABC-subpage-edits

Option 2 is my recommendation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM