Git Rebase and Vim

When collaborating with Git, I find the git fetch, git rebase pattern suits me. I like the cleaner history. Sometimes I'll switch to cherry-pick for applying specific changes for safe deployments.

I used to get into a mess with Vim when using this workflow, because I typically have a lot of open files spread across tabs and windows, so Vim would complain about changes to active buffers. You're probably familiar with this error:

WARNING: The file has been changed since reading it!!!

Sometimes the file isn't even different in terms of content, it's just that Git has moved things around on the filesystem. The solution is simple: reopen the file with :e filename. However, doing that for every file is too much work -- it'd be easier to restart Vim.

That's where :bufdo comes in. Running :bufdo e will make Vim reopen every buffer. That isn't necessarily the best approach because you can have a lot of open buffers that you don't really care about. If that's true, try :windo e -- this executes the command e in each window.

You need to be careful when running these commands. Before running :bufdo or :windo I make sure my files are saved, then I commit my changes, then I git fetch, git rebase, then :windo e.

blog comments powered by Disqus