Skip to content

Instantly share code, notes, and snippets.

@strboul
Last active September 6, 2018 19:37
Show Gist options
  • Save strboul/17010ba988d321d25e4af01101052bd9 to your computer and use it in GitHub Desktop.
Save strboul/17010ba988d321d25e4af01101052bd9 to your computer and use it in GitHub Desktop.
Generate git repo for testing commands
#!/bin/bash
set -e
DIR="/tmp/test-merge"
if [ -d "$DIR" ]; then
rm -rf "$DIR"
fi
mkdir -p $DIR && cd $DIR
git init
git config --local user.email "[email protected]"
git config --local user.name "Merge Tester"
# In merge conflict diff3 shows : your local changes, the
# original file and the remote changes.
git config --local merge.conflictstyle diff3
git config --local merge.tool vimdiff
git config --local mergetool.prompt false
touch file
git add -A && git commit -m 'First commit'
printf "The quick brown fox jumps over the lazy dog\n" > file
git add -A && git commit -m 'Add content file'
git checkout -b wip-branch && git checkout wip-branch
printf "The quick brown bear jumps over the lazy dolphin\n" > file
printf "Eppur si muove\n" >> file
git add -A && git commit -m 'Change file'
git checkout master
printf "Some new content\n" >> file
git add -A && git commit -m 'Add new lines'
# here you should have a merge conflict:
git merge wip-branch
### `git mergetool` using
### Source: https://stackoverflow.com/a/163659
### +----------------------+
### | | | |
### |LOCAL |BASE |REMOTE |
### | | | |
### +----------------------+
### | MERGED |
### | |
### +----------------------+
### 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
### Get changes from
### REMOTE `:diffg RE`
### BASE `:diffg BA`
### LOCAL `:diffg LO`
### `:wqa` save and exit from vim
### `git commit -m "message"`
### `git clean` Remove extra files (e.g. *.orig) created by diff tool.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment