在 git 中切换分支时,如何让 Emacs 恢复所有未更改的缓冲区? [英] How can I get Emacs to revert all unchanged buffers when switching branches in git?

查看:22
本文介绍了在 git 中切换分支时,如何让 Emacs 恢复所有未更改的缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

首先,如果磁盘上的内容与缓冲区中的内容相同,我想找到一种让 emacs 完全不询问我的方法.

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.

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

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 如果有关系的话,我在 OSX 上使用 Aquamacs.

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

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

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

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

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.

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

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.

编辑 2:

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

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.

推荐答案

试试 revbufs 包:

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

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

这篇关于在 git 中切换分支时,如何让 Emacs 恢复所有未更改的缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆