Use vimdiff as git mergetool
2016-08-10 23:09
806 查看
http://www.rosipov.com/blog/use-vimdiff-as-git-mergetool/
Using vimdiff as a git mergetool can be pretty confusing - multiple windows and little explanation. This is a short tutorial which explains basic usage, and what the LOCAL, BASE, and REMOTE keywords mean. This implies
that you have at least a little bit of basic vim knowledge (how to move, save, and switch between split windows). If you don’t, there’s a short article for you: Using
vim for writing code. Some basic understanding of git and branching is required as well, obviously.
This will set git as the default merge tool, will display a common ancestor while merging, and will disable the prompt to open the vimdiff.
Let’s add some animals:
Save the file.
That’s where we get a merge error:
This looks terrifying at first, but let me explain what is going on.
From left to right, top to the bottom:
is file from the current branch
ancestor, how file looked before both changes
result, this is what gets saved in the repo
Let’s assume that we want to keep the “octodog” change (from REMOTE). For that, move to the MERGED file (
This gets the corresponding change from REMOTE and puts it in MERGED file. You can also:
Save the file and quit (a fast way to write and quit multiple files is
Run
you are all set!
Posted by Ruslan Osipov Thu
13 Jun 2013, 7:18 PM vim
Using vimdiff as a git mergetool can be pretty confusing - multiple windows and little explanation. This is a short tutorial which explains basic usage, and what the LOCAL, BASE, and REMOTE keywords mean. This implies
that you have at least a little bit of basic vim knowledge (how to move, save, and switch between split windows). If you don’t, there’s a short article for you: Using
vim for writing code. Some basic understanding of git and branching is required as well, obviously.
Git config
Prior to doing anything, you need to know how to set vimdiff as a git mergetool. That being said:git config merge.tool vimdiff git config merge.conflictstyle diff3 git config mergetool.prompt false
This will set git as the default merge tool, will display a common ancestor while merging, and will disable the prompt to open the vimdiff.
Creating merge conflict
Let’s create a test situation. You are free to skip this part or you can work along with the tutorial.mkdir zoo cd zoo git init vi animals.txt
Let’s add some animals:
cat dog octopus octocat
Save the file.
git add animals.txt git commit -m "Initial commit" git branch octodog git checkout octodog vi animals.txt # let's change octopus to octodog git add animals.txt git commit -m "Replace octopus with an octodog" git checkout master vi animals.txt # let's change octopus to octoman git add animals.txt git commit -m "Replace octopus with an octoman" git merge octodog # merge octodog into master
That’s where we get a merge error:
Auto-merging animals.txt CONFLICT (content): Merge conflict in animals.txt Automatic merge failed; fix conflicts and then commit the result.
Resolving merge conflict with vimdiff
Let’s resolve the conflict:git mergetool
This looks terrifying at first, but let me explain what is going on.
From left to right, top to the bottom:
LOCAL– this
is file from the current branch
BASE– common
ancestor, how file looked before both changes
REMOTE– file you are merging into your branch
MERGED– merge
result, this is what gets saved in the repo
Let’s assume that we want to keep the “octodog” change (from REMOTE). For that, move to the MERGED file (
Ctrl + w, j), move your cursor to a merge conflict area and then:
:diffget RE
This gets the corresponding change from REMOTE and puts it in MERGED file. You can also:
:diffg RE " get from REMOTE :diffg BA " get from BASE :diffg LO " get from LOCAL
Save the file and quit (a fast way to write and quit multiple files is
:wqa).
Run
git commitand
you are all set!
Posted by Ruslan Osipov Thu
13 Jun 2013, 7:18 PM vim
相关文章推荐
- MSP430实现简单的对临界资源的冲突访问
- My97DateTimePicker使用说明
- vim便捷命令:高亮搜索& 多行注释 和 取消多行注释
- R语言-结构控制
- UIWebView、WKWebView使用详解及性能分析
- I/O多路转接之poll,epoll
- 二十个热门的高级Java面试题汇总
- java中关于String类型和double,int类型之间的转换
- oj:深搜+回溯(3)
- 技巧:Vimdiff 使用
- ListView TableView ScrollView三者之Tableview
- 排序一 直接插入排序
- unix环境I/O多路复用
- Kafka学习笔记-Java简单操作
- 数据结构·可持久化线段树
- Hdu 4474 Yet Another Multiple Problem
- JavaScript强化教程 - 六步实现贪食蛇
- 高效使用vimdiff解决git merge冲突(英文版)
- oracle数据库创建、备份
- Android 通过代码创建界面