Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override unmerged git checkout with upstream version

I’m attempting to revert a file modified locally to the version that is most recent upstream, effectively undoing my changes.

$ git checkout --  Jovie/Jovie-Info.plist
error: path ‘Jovie/Jovie-Info.plist' is unmerged

Using -f alters the error to warn, but still won’t make the change (???)

$ git checkout  -f -- Jovie/Jovie-Info.plist
warning: path ‘Jovie/Jovie-Info.plist' is unmerged

The file itself looks like this:

$ git diff Jovie/Jovie-Info.plist
diff --cc Jovie/Jovie-Info.plist
index 6c576d9,0209baa..0000000
--- a/Jovie/Jovie-Info.plist
+++ b/Jovie/Jovie-Info.plist
@@@ -50,7 -50,7 +50,11 @@@
                </dict>
        </array>
        <key>CFBundleVersion</key>
++<<<<<<< Updated upstream
 +      <string>5922</string>
++=======
+       <string>5918</string>
++>>>>>>> Stashed changes
        <key>Fabric</key>
        <dict>
                <key>APIKey</key>

How do I override the local files and apply upstream changes?

like image 259
Maxim Veksler Avatar asked Nov 23 '14 12:11

Maxim Veksler


People also ask

How do you fix pulling is not possible because you have unmerged files?

To fix the “pulling is not possible” error, you can use git reset –hard. Always write a commit message after adding a file to Git's history. Ensure your files are updated to avoid conflict when pulling changes. You need to commit your changes or stash them before you can merge.

Why does git say pull is not possible because you have unmerged files?

So now, when you do a git pull , git is throwing up the error, because you have some version of the file, which is not correctly resolved. To resolve this, you will have to resolve the merge conflicts in question, and add and commit the changes, before you can do a git pull .

How do you discard local changes and pulls from a remote?

There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.


1 Answers

You might need to reset the file first, before doing the checkout:

git reset -- Jovie/Jovie-Info.plist
git checkout -- Jovie/Jovie-Info.plist

The reset un-stage the changes in progress (here the merge, with the conflict markers in the file).
Then the checkout can restore the index with the last commit content.

like image 126
VonC Avatar answered Jan 18 '23 22:01

VonC