在 git 中切换分支时,如何让 Emacs 恢复所有未更改的缓冲区?

发布于 2024-07-14 22:31:50 字数 769 浏览 6 评论 0原文

通常,当我在 git 中切换分支时,如果文件在 emacs 中打开,那么 emacs 会询问我是否要恢复它们(因为它认为它们在磁盘上已更改),即使内容相同。

首先,我想找到一种方法,如果磁盘上的内容与缓冲区中的内容相同,则 emacs 根本不会询问我。

其次,我想要一个命令来恢复(不查询)所有没有未保存更改的打开缓冲区,并询问我是否有未保存更改。

或者,我愿意接受有关我可以尝试的其他解决方案、工作方式等的建议。 如果人们能指导我从哪里开始,我会很高兴编写 emacs-lisp。

PS 如果这很重要的话,我在 OSX 上使用 Aquamacs。

编辑:

嗯,我发现 revbuffs 包几乎就是我所需要的。 当然足以阻止我自己尝试写任何新东西。 (我将 revbuffs 映射到 Cmd-R,效果非常好。有点类似于其他 Mac 应用程序中的 Cmd-R)。

全局自动恢复模式将是一个完美的解决方案,我希望我可以选择两个答案。 我更喜欢转速增益,只是因为有一种想要控制所发生的事情的感觉,这可能是非理性的。

我有点猜测,如果我从 emacs 中访问 git,那么它可能会更容易处理,但我目前更喜欢通过命令行访问 git。 (我使用 emacs 的时间还不够长,还不足以让它成为我的操作系统)。 不过我会更彻底地研究magit。

Edit2:

我已经使用 Magit 一年了,强烈推荐它在 emacs 中处理 git。 然而,每当我在 emacs 之外进行 rebase 时,我仍然使用 revbuff。

Often, when I switch branches in git, if the files are open in emacs, then emacs asks if I want to revert them (as it thinks they've changed on disk) even though the contents are identical.

Firstly I'd like to find a way for emacs to not ask me about it at all if the contents on disk are identical to those in the buffer.

Secondly I'd like a command that reverted (without query) all my open buffers that have no unsaved changes, and queried me about those that do have unsaved changes.

Alternatively, I'd be open to suggestions about other solutions, ways of working, etc I could try. I'm fairly happy writing emacs-lisp if people can give me pointers on where to start.

PS I'm using Aquamacs on OSX if that matters.

Edit:

Well, I've found the revbuffs package to be pretty much what I need. Certainly enough to stop me wanting to try and write anything new myself. (I mapped revbuffs to Cmd-R which works quite nicely. Kind of similar to Cmd-R in other Mac apps).

Global-auto-revert mode would have been a perfectly fine solution, and I wish I could choose two answers. I prefer revbuffs simply because of a, possibly irrational, feeling of wanting to be in control of what happens.

I'd kind of guessed that if I accessed git from within emacs, then it could probably be handled easier, but I currently prefer accessing git through the commandline. (I haven't quite been using emacs long enough to make it my operating system). I will investigate magit a little more thoroughly though.

Edit2:

I've been using magit for a year now and can highly recommend it for dealing with git from within emacs. However I still use revbuffs whenever I do a rebase outside of emacs.

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

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

发布评论

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

评论(3

纵情客 2024-07-21 22:31:50

也许您想要全局自动恢复模式。 尝试运行 global-auto-revert-mode,如果您喜欢,可以将 (global-auto-revert-mode) 添加到 ~/.emacs 文件中。

Perhaps you'd like the global auto-revert mode. Try running global-auto-revert-mode and if you like it you can add (global-auto-revert-mode) to your ~/.emacs file.

樱&纷飞 2024-07-21 22:31:50

尝试 revbufs 包

revbufs.el 是一个小型 Emacs 包,当您在 Emacs 中或通过外部工具(例如,代码生成器,如 Jomtool)...

Try the revbufs package:

revbufs.el is a tiny Emacs package that safely reverts your buffers when you have files being edited both in Emacs and via external tools (e.g., code generators such as Jomtool)...

羅雙樹 2024-07-21 22:31:50

Magit package do this automatically, when you activate magit-ionotify-mode (inotify need emacs 24.4 on linux). Its description you can find here.

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