git reset --hard origin/master 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38536896/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:23:37  来源:igfitidea点击:

git reset --hard origin/master failing

git

提问by Caes

Trying to discard changes on server, and make it exactly the same as origin/master:

尝试丢弃服务器上的更改,并使其与 origin/master 完全相同:

git fetch --all
git reset --hard origin/master

I've done this before on same repo without problems, but this time it fails with the following:

我之前在同一个 repo 上做过这个没有问题,但这次失败了:

fatal: Could not reset index file to revision 'origin/master'

Have tried the following:

尝试了以下方法:

  1. remove index and reset as suggested here:

    rm .git/index
    git reset
    
  2. also suggested herethat some process could have a lock on .git\index. That killing process and then executing git resetcould fix it, but not sure how to check if something has a lock on file remotely. Also seems that removing index file and reset would have had same effect.

  1. 删除索引并按照此处的建议重置:

    rm .git/index
    git reset
    
  2. 此处还建议某些进程可以锁定 .git\index。杀死进程然后执行git reset可以修复它,但不确定如何远程检查某些东西是否锁定了文件。似乎删除索引文件和重置也会产生相同的效果。

Loosing my mind. Would really appreciate any help.

失去理智。真的很感激任何帮助。

回答by RZ87

Had the same issue, which quite crazy cause reset --hardshould always work, but it seems the working tree had a lot of differences to my target branch.

有同样的问题,这很疯狂的原因reset --hard应该总是有效,但似乎工作树与我的目标分支有很多不同。

I had no time to dig this down, butfound this by accident:

我没有时间挖掘这个,但偶然发现了这个:

First run git gcto do some garbage collection. It will remove unnecessary files and optimize the local repository (more info about git gccan be found here).

首先运行git gc进行一些垃圾收集。它将删除不必要的文件并优化本地存储库(git gc可以在此处找到更多信息)。

Then simple resetand finally reset --hardto desired branch.

然后简单reset,最后reset --hard到所需的分支。

$ git gc

$ git reset

$ git reset --hard <target_branch>

回答by AleksandrH

Just wanted to note that this ended up being the source of my problem:

只是想指出,这最终成为我问题的根源:

also suggested here that some process could have a lock on .git\index. That killing process and then executing git reset could fix it, but not sure how to check if something has a lock on file remotely. Also seems that removing index file and reset would have had same effect.

此处还建议某些进程可以锁定 .git\index。杀死进程然后执行 git reset 可以修复它,但不确定如何远程检查某些东西是否锁定了文件。似乎删除索引文件和重置也会产生相同的效果。

If you're running anything on local, like Jekyll, React, etc. that has a lock on the files in your project, then killing that process with Ctrl+C/Cmd+Cwill do the trick.

如果你在本地运行任何东西,比如 Jekyll、React 等,对你项目中的文件有锁定,那么用Ctrl+ C/ Cmd+终止该进程C就可以了。

回答by Erik Forsstr?m

I had the same problem and realized that I had run out of disk space...

我遇到了同样的问题,并意识到我的磁盘空间不足...