如何使用上游版本覆盖未合并的 git checkout
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27089095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to override unmerged git checkout with upstream version
提问by Maxim Veksler
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 (???)
使用 -f 将错误更改为警告,但仍然不会进行更改 (???)
$ 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?
如何覆盖本地文件并应用上游更改?
回答by VonC
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.
重置取消暂存正在进行的更改(这里是合并,文件中有冲突标记)。
然后结帐可以使用最后提交的内容恢复索引。
回答by Thiago Navarro
If you need to do for all both modifiedunmerged files , there is a simple way to do that instead of doing for each one:
如果您需要对所有已修改的未合并文件都执行此操作,则有一种简单的方法可以做到这一点,而不是对每个文件都执行:
git reset $( git status | grep both | awk '{print }')
git checkout $( git status | grep modified | awk '{print }')
If you need to do for all [added/deleted] by usunmerged files , there is a simple way to do that instead of doing for each one:
如果您需要对我们未合并的文件的所有[添加/删除] 执行此操作,有一种简单的方法可以做到这一点,而不是对每个文件都执行:
git reset $( git status | grep us | awk '{print }')
git checkout $( git status | grep modified | awk '{print }')
If you need to do for all [added/deleted] by themunmerged files , there is a simple way to do that instead of doing for each one:
如果您需要对所有[已添加/删除] 的未合并文件执行此操作,则有一种简单的方法可以做到这一点,而不是对每个文件都执行:
git reset $( git status | grep them | awk '{print }')
git checkout $( git status | grep modified | awk '{print }')