forked from jwiegley/git-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-rm-conflicts
executable file
·62 lines (54 loc) · 1.56 KB
/
git-rm-conflicts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# git-rm-conflicts, version 1.3
#
# by John Wiegley <[email protected]>
#
# Run without arguments to see usage.
if [[ -z "$1" ]]; then
cat <<EOF
usage: git rm-conflicts ours|theirs FILES...
With 'ours', delete conflicts coming from the current branch (aka HEAD).
With 'theirs', delete conflicting code from the commits you're trying to
merge in.
Example:
$ git checkout master
$ git merge foo
<lots of conficts from foo I don't care about>
$ git rm-conflicts ours FILE1 FILE2
<delete conflicts in FILE1 and 2, but check the others>
NOTE: You almost never want to use this command, but instead should
check why exactly your files are conflicting. Use of this script is
almost guaranteed to throw away code you don't want to throw away!!
But if you need it, here it is.
EOF
exit 1
fi
recursed=false
if [[ "$1" == --recursed ]]; then
recursed=true
shift 1
fi
if [[ "$1" == ours ]]; then
shift 1
wipe=ours
elif [[ "$1" == theirs ]]; then
shift 1
wipe=theirs
else
echo error: Must specify which set of changes to remove: ours or theirs
exit 1
fi
for item in "$@"; do
if [[ -d "$item" && $recursed == false ]]; then
if [[ $(basename "$item") != .git ]]; then
git ls-files -z -u "$item" | xargs -0 $0 --recursed $wipe
fi
elif [[ -f "$item" ]]; then
echo Removing $wipe from: $item
if [[ $wipe == ours ]]; then
perl -i -ne 'print unless /<<<<<</ .. /======/ or />>>>>>/;' "$item"
elif [[ $wipe == theirs ]]; then
perl -i -ne 'print unless /<<<<<</ or /======/ .. />>>>>>/;' "$item"
fi
fi
done