撤消 git-lfs 中的本地更改

发布于 2025-01-10 21:19:48 字数 591 浏览 0 评论 0原文

我有一个包含本地更改的 git-lfs 存储库,我想丢弃它们。我尝试了以下命令但没有成功:

git checkout file

git checkout -- file

git lfs checkout file

git reset --hard< /code>

我应该使用什么命令?

谢谢!

编辑:

使用 gitk 查看修改显示所有文件的 r/w 属性都已更改。内容相同。

-------------------- .gitattributes --------------------
old mode 100644
new mode 100755

还尝试了这里提到的建议但没有成功: git重置后未暂存的更改 --hard

I have a git-lfs repo with local changes and I want to discard them. I tried the following command without success:

git checkout file

git checkout -- file

git lfs checkout file

git reset --hard

What command should I use?

Thanks!

EDIT:

Viewing the modifications with gitk revealed that r/w attributes were changed for all files. Contents are identical.

-------------------- .gitattributes --------------------
old mode 100644
new mode 100755

Also tried the suggestions mentioned here without success:
Unstaged changes left after git reset --hard

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

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

发布评论

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

评论(1

夜吻♂芭芘 2025-01-17 21:19:48

TL;DR

您可能手动将 core.fileMode 设置为 true。将其设置回false

长的

使用 gitk 查看修改显示所有文件的 r/w 属性都已更改。内容相同。

-------------------- .gitattributes --------------------
旧模式100644
新模式100755

git reset --hard 也会尝试更改模式。显然这次尝试失败了,也许没有报告任何错误。

这种行为常见于 DOS/Windows 风格的文件系统,其中根本不支持 +x 和 -x 模式。某些适配器将所有文件报告为模式 644 (rw-r--r--),某些适配器将所有文件报告为模式 755 (rwx-r-xr -x);看起来你有第二种。

Git 通常会针对这些类型的文件系统进行自我检测和调整:在创建存储库时,Git 会进行一些“创建文件并更改其模式”测试。如果模式从 +x 更改为 -x 和/或反之亦然,Git 认为操作系统和文件系统确实支持模式,因此它设置一个配置设置:

core.fileMode true

如果这些更改< em>不遵守,Git认为操作系统和文件系统支持模式,因此设置相反的设置:

core.fileMode false

请注意,此设置core.filemode code> (有时采用混合驼峰式命名,有时采用全小写形式: Git 在这里不区分大小写,但在其他地方则不然),告诉 Git 你的系统如何工作。它不控制系统,它只是报告早期的观察结果

如果您手动更改此变量,您就是在告诉 Git 您已经更换了操作系统和/或文件系统,并且现在它以其他方式工作。如果您确实更换了操作系统和/或文件系统并且它确实以其他方式工作,则您的新设置是正确的。但如果没有,那么你现在就对 Git 撒了谎。

或者,您可以将整个 .git 存储库和工作树移动到新的文件系统。当您执行此操作时,根据您的特定操作系统和文件系统,旧的 core.fileMode 设置现在可能不准确。 Git 不会知道这一点——Git 会相信旧的设置。通过移动文件,您实际上对 Git 撒了谎,尽管在这种情况下您可能没有任何理由怀疑类似的事情。

在这两种情况下,解决方法都是纠正谎言:通过将 core.fileMode 设置为 false 或 true 来告知 Git 文件系统的实际工作原理> 适当地。一旦正确设置,Git 将知道是否假设它看到的属性设置有效 (core.fileMode true),因此您会看到这种更改,或者不会 (core.fileMode true)。 fileMode false),因此您不会看到这种变化。

TL;DR

You probably manually set core.fileMode to true. Set it back to false.

Long

Viewing the modifications with gitk revealed that r/w attributes were changed for all files. Contents are identical.

-------------------- .gitattributes --------------------
old mode 100644
new mode 100755

The git reset --hard will have attempted to change the mode as well. Apparently this attempt failed, perhaps without any errors being reported.

This behavior is commonly seen on DOS/Windows-style file systems, where +x and -x modes are simply not supported. Some adapters report all files as mode 644 (rw-r--r--) and some adapters report all files as mode 755 (rwx-r-xr-x); it looks like you have the second kind.

Git normally detects and adjusts itself for these kinds of file systems: at the time the repository is created, Git does a few "create a file and change its mode" tests. If the mode changes from +x to -x and/or vice versa are obeyed, Git believes that the OS and file system do support modes, and it therefore sets a configuration setting:

core.fileMode true

If these changes are not obeyed, Git believes that the OS and file system do not support modes, and it therefore sets the opposite setting:

core.fileMode false

Note that this setting, core.filemode (sometimes in mixed camelCase and sometimes all lowercase: Git is case-insensitive here, though not elsewhere), tells Git how your system works. It does not control the system, it simply reports the earlier observation.

If you, manually, change this variable, you're telling Git that you have replaced your operating system and/or file system, and it now works the other way. If you did in fact replace your OS and/or file system and it does work the other way, your new setting is correct. But if not, you have now lied to Git.

Or, you might take your entire .git repository and working tree and move them to a new file system. When you do that, depending on your particular OS and file systems, it's possible that the old core.fileMode setting is now inaccurate. Git won't know this—Git will believe the old setting. By moving the files, you have, in effect, lied to Git, though in this case you probably didn't have any reason to suspect something like that.

In both cases, the fix is to correct the lie: inform Git how the file system really works, by setting core.fileMode to false or true appropriately. Once it's set correctly, Git will know whether to assume the attributes settings it sees are valid (core.fileMode true) and therefore you'll see this kind of change, or not (core.fileMode false) and therefore you won't see this kind of change.

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