Last active
July 26, 2023 13:29
-
-
Save emakarov/9924c6f57912cb36fb2509c5f90f82ae to your computer and use it in GitHub Desktop.
Python script that can resolve all git conflicts in some file marked with conflicts based on chosen strategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
accept = 'ours' # ours for 'HEAD' #theirs for other's - choose strategy here for all conflicts | |
filename = 'enter your filename here' | |
fresult = '{}.{}'.format(filename, 'merged') # result will be near your file with name `original_filename.ext.merged` | |
with open(filename) as f: | |
content = f.readlines() | |
res = open(fresult, 'w') | |
to_write = True | |
merging = False | |
special_line = False | |
i = 0 | |
for c in content: | |
i += 1 | |
if c.startswith('<<<<<<< HEAD'): | |
special_line = True | |
merging = True | |
if accept == 'ours': | |
to_write = True | |
print('line {} accepting HEAD'.format(i)) | |
else: | |
to_write = False | |
print('line {} accepting THEIRS'.format(i)) | |
elif c.startswith('======='): | |
special_line = True | |
merging = True | |
if accept == 'ours': | |
to_write = False | |
else: | |
to_write = True | |
elif c.startswith('>>>>>>>'): | |
special_line = True | |
merging = False | |
to_write = True | |
else: | |
special_line = False | |
if to_write and not special_line: | |
res.write(c) | |
res.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this script.