在 git 中切换分支时,如何让 Emacs 恢复所有未更改的缓冲区?
通常,当我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您想要全局自动恢复模式。 尝试运行
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.尝试 revbufs 包:
Try the revbufs package:
当您激活
magit-ionotify-mode
< 时,Magit 包会自动执行此操作/a> (inotify 在 Linux 上需要 emacs 24.4)。 您可以在此处找到其说明。Magit package do this automatically, when you activate
magit-ionotify-mode
(inotify need emacs 24.4 on linux). Its description you can find here.