Git拒绝重置/放弃文件 [英] Git refuses to reset/discard files

查看:187
本文介绍了Git拒绝重置/放弃文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我无法更新的某些js文件的项目。我在本地运行OSX,并且远程/临时服务器是Linux(CentOS)。



在本地克隆我的项目后,我注意到我拥有所有那些git status 修饰。我从来没有修改它们,所以我试图放弃更改 reset 它们,但它们再次出现。修改中的更改是删除所有行并重新添加它们。



我不确定为什么会发生这种情况,或者如何解决这个问题,这样我的git状态就可以保持干净。


$

 #modified:app / webroot / js / ckeditor /plugins/devtools/lang/el.js 
#modified:app / webroot / js / ckeditor / plugins / devtools / lang / fa.js
#modified:app / webroot / js / ckeditor / plugins /devtools/lang/gu.js

更新1:



现在我已经设法提交上述文件,但暂存服务器已被锁定,因为它不会提取新的编辑:

 <$ 
app / webroot / js / ckeditor / _source / lang / ar.js
app / webroot / js / ckeditor / c $ c>错误:您将对以下文件的本地更改进行合并: _source / lang / bg.js
app / webroot / js / ckeditor / _source / lang / bn.js
app / webroot / js / ckeditor / _source / lang / cs.js
。 ..
正在取消

我无法提交/推送,因为:

 更新被拒绝是因为推送的分支提示位于其远程对象背后

我试过了:

  git reset --hard 

  git stash 
git stash drop

但它们不起作用,没有任何反应。

更新2:

git diff 给出我:

 该文件的原始行结束符在您的工作目录中。 
警告:在app / webroot / js / ckeditor / _source / lang / fa.js中,CRLF将被替换为LF。
该文件将在工作目录中具有其原始行结尾。
警告:在app / webroot / js / ckeditor / _source / lang / gu.js中,CRLF将被替换为LF。
该文件将在工作目录中具有其原始行结尾。
...


解决方案

/ h2>


修改中的更改是删除所有行并重新添加。


这是因为换行符在提交的文件和磁盘上的文件之间发生了变化。

Github有一个手册页详细说明了如何处理这类问题,简而言之(对于linux / OSX),第一步是git config --global core.autocrlf input $ b更改您的git配置,以便为您排序行结尾:

  git config --global core.autocrlf input 

然后提交行尾标准化:

  git rm --cached -r。 
#从索引中删除所有内容。

git reset --hard
#从git的数据库中写入索引和工作目录。

git add。
#准备通过暂存所有将被标准化的文件进行提交。
#这是您检查哪些文件从未标准化的机会。你应该
#得到很多消息,例如:警告:CRLF将被文件中的LF替换。

git commit -m标准化行结束
#提交



<然后,行结尾应该正确处理。请参阅github上的帮助页面以获得更多信息,或者查看git文档的相关部分格式化和whitespace


解决linux-machine冲突问题

lockquote

服务器被锁定,因为它不会提取新的编辑。


错误信息为您对本地文件的更改将被覆盖通过合并:,这意味着它们包含本地更改,应该在继续之前提交或丢弃。假定登台服务器正常使用(它没有任何有意的更改),则可以放弃本地更改。例如,执行以下操作:

  $ git fetch origin 
#检索更新

$ git reset --hard origin / master
#强制更改当前分支以匹配origin / master

这将检索存储库历史记录,而不更新工作副本,然后进行更新以与存储库中的主分支完全匹配。请注意,最后一条命令将放弃所有未提交的更改。


I have a project with certain js files which I cannot update. I run OSX locally and my remote/staging server is Linux (CentOS).

Right after cloning my project locally, i noticed I have all those files with git status modified. I never modified them, so I tried to discard changes or reset them, but they come up again. The change that is in the modification is deleting all lines and adding them again.

I'm not sure why this happens or how to fix it so that my git status is clean as it needs to be.

Here is a few lines from the git status:

#   modified:   app/webroot/js/ckeditor/plugins/devtools/lang/el.js
#   modified:   app/webroot/js/ckeditor/plugins/devtools/lang/fa.js
#   modified:   app/webroot/js/ckeditor/plugins/devtools/lang/gu.js

UPDATE 1:

I have now managed to commit the above files, but the staging server is locked because it won't pull new edits:

error: Your local changes to the following files would be overwritten by merge:
    app/webroot/js/ckeditor/_source/lang/ar.js
    app/webroot/js/ckeditor/_source/lang/bg.js
    app/webroot/js/ckeditor/_source/lang/bn.js
    app/webroot/js/ckeditor/_source/lang/cs.js
    ...
Aborting

I can't commit/push because:

Updates were rejected because a pushed branch tip is behind its remote counterpart

I tried:

git reset --hard

and

git stash
git stash drop

But they don't work, nothing happens.

UPDATE 2:

git diff gives me:

The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/webroot/js/ckeditor/_source/lang/fa.js.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/webroot/js/ckeditor/_source/lang/gu.js.
The file will have its original line endings in your working directory.
...

解决方案

Normalize line endings

The change that is in the modification is deleting all lines and adding them again.

This is because the newlines are being changed between the committed files and the files on disk.

Github has a handy page detailing how to deal with this kind of problem, in brief (for linux/OSX), step one is to change your git config so it sorts out the line endings for you:

git config --global core.autocrlf input

Then commit line-endings normalization:

git rm --cached -r .
# Remove everything from the index.

git reset --hard
# Write both the index and working directory from git's database.

git add .
# Prepare to make a commit by staging all the files that will get normalized.
# This is your chance to inspect which files were never normalized. You should
# get lots of messages like: "warning: CRLF will be replaced by LF in file."

git commit -m "Normalize line endings"
# Commit

And then, line endings should be handled correctly. See the help page on github for more information, or the relevant section of the git docs formatting and whitespace.

Resolving linux-machine conflicts

the staging server is locked because it won't pull new edits.

The error message reads "Your local changes to the following files would be overwritten by merge:", that means they contain local changes which should either be committed or discarded before continuing. Assuming normal usage for the staging server (it doesn't have any intentional changes) the local changes can be discarded. For example do the following:

$ git fetch origin
# Retrieve updates

$ git reset --hard origin/master
# Forcibly change the current branch to match origin/master

This will retrieve the repository history, without updating the working copy, and then update to exactly match the master branch in the repository. Note that the last command will discard all uncommitted changes.

这篇关于Git拒绝重置/放弃文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆