我有一个项目包含某些我无法更新的js文件。我在本地运行OSX,而我的远程/临时服务器是Linux(CentOS)。
在本地克隆我的项目之后,我注意到我拥有git status modified
的所有文件。我从未修改它们,所以我尝试discard changes
或reset
它们,但它们再次出现。修改中的更改是删除所有行并再次添加它们。
我不确定为什么会发生这种情况或如何解决这个问题,以便我的git状态是干净的。
以下是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:
我现在设法提交了上述文件,但登台服务器已被锁定,因为它不会进行新的编辑:
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
我无法提交/推送,因为:
Updates were rejected because a pushed branch tip is behind its remote counterpart
我试过了:
git reset --hard
和
git stash
git stash drop
但它们不起作用,没有任何反应。
更新2:
git diff
给了我:
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.
...
答案 0 :(得分:102)
修改中的更改是删除所有行并再次添加。
这是因为在提交的文件和磁盘上的文件之间更改了换行符。
Github有一个handy page详细说明如何处理这类问题,简而言之(对于linux / OSX),第一步是更改你的git配置,以便为你排序行结束:
git config --global core.autocrlf input
然后提交行结束标准化:
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
然后,应该正确处理行结尾。有关详细信息,请参阅github上的帮助页面,或git docs formatting and whitespace的相关部分。
登台服务器已锁定,因为它不会进行新的编辑。
错误消息显示“您对以下文件的本地更改将被merge覆盖:”,这意味着它们包含本地更改,应在继续之前提交或丢弃。假设登台服务器正常使用(它没有任何有意的更改),可以放弃本地更改。例如,执行以下操作:
$ git fetch origin
# Retrieve updates
$ git reset --hard origin/master
# Forcibly change the current branch to match origin/master
这将检索存储库历史记录,而不更新工作副本,然后更新以与存储库中的主分支完全匹配。请注意,最后一个命令将丢弃所有未提交的更改。
答案 1 :(得分:13)
我总是提到确保您的core.autocrlf
设置为false
,如“Git : stuck repo using stash after crlf normalization?”
git config --global core.autocrlf false
另外,请确保您没有.gitattributes
文件,其eol
指令会尝试转换行尾。
基本想法是:当您确定没有自动转换任何类型时,您是否仍会看到该错误消息?
但为了以防万一,还要考虑“Git rebase fails, 'Your local changes to the following files would be overwritten by merge'. No local changes?”
我在Mac上,这个模糊的配置更改似乎解决了我没有关于无阶段更改的困境。
git config --global core.trustctime false
答案 2 :(得分:8)
我在同一个问题上花了2个小时(!)使用.svg文件(标量矢量图形),在没有我干预的情况下,'恢复'之后不断变化。
因此该文件在'git status'中显示为已修改;恢复它成功,但它不断变化,所以'拉'一次又一次失败......太烦人了!
'git reset','git ignore','git untrack'等没有运气......
最后,我通过从本地系统中删除文件解决了这个问题(不是'git delete',只是Shift + Delete)>>现在'pull'请求传递,文件从远程存储库中获取。
这么容易,我可以哭!
答案 3 :(得分:4)
这个问题在Ubuntu机器上反复弹出Roll20字符表存储库,我可以通过
解决它.gitattributes
但是,今天完全解决了这个问题,通过查看Stack Overflow,我发现罪魁祸首是他们的# Auto detect text files and perform LF normalization
* text=auto
文件:
git pull origin master
git status
后,On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Star Wars Revised RPG/SWRRPG-updated.html
no changes added to commit (use "git add" and/or "git commit -a")
返回:
* text=auto
解决方案是从.gitattributes中删除$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .gitattributes
no changes added to commit (use "git add" and/or "git commit -a")
行:
.gitattributes
git status
上的更改可以被丢弃,Git仍然会得到满足。
编辑+ 1d :今天重新尝试.gitattributes“技巧”,但在放弃.gitattributes更改之前没有git status
。对我来说没有任何明显的理由(可能缓存git status
?),之后On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Star Wars Revised RPG/SWRRPG-updated.html
no changes added to commit (use "git add" and/or "git commit -a")
再次返回此内容:
git status
再次这样做,但中间有android:windowSoftInputMode="stateVisible|adjustPan"
。