9

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?

nav
  • 410
  • 6
  • 14
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
  • Possible duplicate of [Git: can't undo local changes (error: path ... is unmerged)](http://stackoverflow.com/questions/3021161/git-cant-undo-local-changes-error-path-is-unmerged) – Stewart Apr 04 '17 at 10:10

2 Answers2

22

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
5

If you need to do for all both modified unmerged files , there is a simple way to do that instead of doing for each one:

git reset $( git status | grep both | awk '{print $4}')
git checkout $( git status | grep modified | awk '{print $3}')

If you need to do for all [added/deleted] by us unmerged files , there is a simple way to do that instead of doing for each one:

git reset $( git status | grep us | awk '{print $5}')
git checkout $( git status | grep modified | awk '{print $3}')

If you need to do for all [added/deleted] by them unmerged files , there is a simple way to do that instead of doing for each one:

git reset $( git status | grep them | awk '{print $5}')
git checkout $( git status | grep modified | awk '{print $3}')
nav
  • 410
  • 6
  • 14