gpt4 book ai didi

Git 拒绝重置/丢弃文件

转载 作者:IT王子 更新时间:2023-10-29 00:33:17 29 4
gpt4 key购买 nike

我有一个项目,其中包含我无法更新的某些 js 文件。我在本地运行 OSX,我的远程/暂存服务器是 Linux (CentOS)。

在本地克隆我的项目后,我注意到所有这些文件都带有 git status modified。我从未修改过它们,所以我尝试放弃更改重置它们,但它们又出现了。修改中的更改是删除所有行并再次添加它们。

我不确定为什么会发生这种情况或如何修复它,以便我的 git status 保持干净。

这里是 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

更新 1:

我现在已经成功提交了上述文件,但是登台服务器被锁定,因为它不会 pull 新的编辑:

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.
...

最佳答案

规范化行尾

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

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

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 文档的相关部分 formatting and whitespace .

解决 linux 机器冲突

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

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

$ git fetch origin
# Retrieve updates

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

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

关于Git 拒绝重置/丢弃文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18536863/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com