切换git分支时如何处理vim缓冲区? [英] How do I deal with vim buffers when switching git branches?

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

问题描述

因此,我在vim缓冲区中打开了大量文件,我正在使用git开发一个功能分支。突然,我意识到我需要恢复到我的主分支来快速修复。



完成我的提交后,我将vim会话打开并切换回来到主分支。但是,当我尝试从缓冲区中加载需要的文件时,我现在收到消息

 警告:文件<文件名>中编辑开始后已改变

这对我来说是完整的。缓冲区中的文件来自我的功能分支,现在我已切换回主分支,可以理解一些增量处理。



我的问题是,这种情况如何在专业级别上处理?



考虑解决方案,我可以关闭所有缓冲区并重新打开文件。但是,我希望有一个聪明的方式来做到这一点。有没有办法将当前vim缓冲区中的文件替换为所需分支中的对应文件?有没有办法维护多个缓冲区,每个git分支一个?



最终,我希望能够在git分支之间切换,并且打开vim会话只是知道哪个版本的文件当前应该驻留在缓冲区中。



其中的一部分是我仍然在学习vim缓冲区的工作原理,并且刚刚开始使用他们广泛。所以如果我做出了任何不成立的假设,请在适当的地方纠正我。 您可以做一个:bufdo e 强制vim重新读取文件系统中的所有打开缓冲区。


$ b

bufdo code>是一种将命令应用于多个缓冲区的方法。 (同样,如果你使用的是制表符, tabdo

所以它会替换旧版本的分支由新分支的版本。



(类似的问题和答案在那里: Git在文件打开时分支


So, I've got a ton of files open in my vim buffer, and I'm working on a feature branch with git. Suddenly, I realize that I need to revert back to my master branch to make a quick fix.

After making my commits, I leave my vim session open and switch back over to the master branch. However, when I try and load the files I need from the buffer, I now get the message

Warning: File "<filename>" has changed since editing started

This makes complete since to me. The file in the buffer is from my feature branch, and now that I have switched back to master branch, there are understandably some deltas to deal with.

My question is, how is this situation dealt with on a professional level?

Thinking of solutions, I could just close all the buffers and re-open the files. However, I was hoping there is a "smart" way to do this. Is there a way to replace the files in the current vim buffer with their counterparts in the desired branch? Is there a way of maintaining multiple buffers, one per git branch?

Ultimately, I want to be able to switch between git branches, and have the open vim session just "know" which version of the file should currently reside in the buffer.

Part of this is that I am still learning about how vim buffers work, and have just started to use them extensively. So if I made any assumptions that don't hold, please correct me where appropriate.

解决方案

You can do a :bufdo e to force vim to reread all the open buffer from the filesystem.

bufdo is a way to apply a command to multiple buffers. (Similarly there is a tabdo if you are using tabs)

So it will replace the version of the old branch by the version of the new branch.

(Similar question & answer there : Git branching while files are opened )

这篇关于切换git分支时如何处理vim缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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