如何摆脱 git 中的虚假更改?

发布于 2024-09-06 00:38:22 字数 520 浏览 4 评论 0原文

我是 PortableGit 1.7.0.2 的快乐用户。今天我想从 GitHub.com 存储库中提取项目更改,所以我执行了 git pull 。它失败并显示以下消息:错误:您对“main.rb”的本地更改将被合并覆盖。正在中止。。我不关心本地更改,所以我输入了 git reset --hard HEAD (git clean 从这里也没有帮助),但它不起作用。当询问 git status 时,我仍然能够看到文件已修改。 git diff 显示文件的每一行都已被修改,而 git diff -b 显示没有任何差异,所以我猜这是一个行结束问题。这很奇怪,因为代码仅是从 Windows 机器推送的。

无论如何,问题是:如何忽略本地的虚假更改并与远程存储库中的最新更改合并?

I'm a happy user of PortableGit 1.7.0.2. Today I wanted to pull a project changes from GitHub.com repository, so I did git pull. It failed with the following message: error: Your local changes to 'main.rb' would be overwritten by merge. Aborting.. I didn't care about the local changes so I typed git reset --hard HEAD (git clean from here didn't help neither), but it didn't work. When asked for git status I was still able to see the file as modified. git diff showed me that each line of the file has been modified, while git diff -b showed no differences at all, so I guess this is a line ending issue. Which is strange because the code is only pushed from Windows machines.

Anyway, the question is: how can I ignore the local, bogus changes and merge with the latest changes from the remote repository?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2024-09-13 00:38:22

首先,您是否尝试过 git clean -f(注意“-f”)?
git config 手册页:

clean.requireForce

一个布尔值,使 git-clean 不执行任何操作,除非给出 -f-n默认为 true

其次,您是否将 autocrlf 设置设置为 false 正如我在这个问题中提到的
(即使从 Windows 机器推送到 Windows PC,带有 Unix eol 的文本文件也会转换为 Windows eol)

考虑到这两点,您应该能够拉取。

First, did you try a git clean -f (note the '-f')?
From git config man page:

clean.requireForce

A boolean to make git-clean do nothing unless given -f or -n. Defaults to true.

Second, did you set your autocrlf setting to false as I mention in this question?
(even if pushed from a Windows machine to a Windows PC, a text file with Unix eol would be converted to Windows eol)

With those two points taken care of, you should be able to pull.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文