{"id":19063029,"url":"https://github.com/jakub-g/git-resolve-conflict","last_synced_at":"2025-03-31T10:04:32.149Z","repository":{"id":46049030,"uuid":"66462441","full_name":"jakub-g/git-resolve-conflict","owner":"jakub-g","description":" :heavy_dollar_sign: :heavy_plus_sign: :heavy_minus_sign: :white_check_mark: Resolve merge conflict from command line, in one file, using given strategy (--ours, --theirs, --union)","archived":false,"fork":false,"pushed_at":"2025-01-20T15:32:55.000Z","size":35,"stargazers_count":52,"open_issues_count":4,"forks_count":10,"subscribers_count":2,"default_branch":"base","last_synced_at":"2025-03-26T22:46:55.451Z","etag":null,"topics":["conflict-resolution","conflicting-changes","git","git-mergetools","merge-conflicts","resolve-conflicts"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakub-g.png","metadata":{"files":{"readme":"README-extended.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-24T12:34:02.000Z","updated_at":"2025-02-25T08:50:24.000Z","dependencies_parsed_at":"2025-02-28T14:17:23.667Z","dependency_job_id":"5c5421f6-17f9-436f-b661-46185044e679","html_url":"https://github.com/jakub-g/git-resolve-conflict","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fgit-resolve-conflict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fgit-resolve-conflict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fgit-resolve-conflict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fgit-resolve-conflict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakub-g","download_url":"https://codeload.github.com/jakub-g/git-resolve-conflict/tar.gz/refs/heads/base","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246450462,"owners_count":20779408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conflict-resolution","conflicting-changes","git","git-mergetools","merge-conflicts","resolve-conflicts"],"created_at":"2024-11-09T00:28:39.801Z","updated_at":"2025-03-31T10:04:32.128Z","avatar_url":"https://github.com/jakub-g.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nInitial situation\n=================\n\n    $ git log --oneline base\n    be4abab add git-resolve-conflict script\n    ...\n\n    $ git log --oneline master\n    0ea4d05 1.0.2\n    d94a1dc change in master: add dependencies\n    386ae99 1.0.1\n    6160dea change in master\n    be4abab add git-resolve-conflict script\n    ...\n\n    $ git log --oneline develop\n    f2fefc6 2.0.1\n    b8c66c9 change in develop\n    263aa5f 2.0.0\n    be4abab add git-resolve-conflict script\n    ...\n\nGoal\n=================\n\nWe want to merge `develop` into `master` and auto-resolve conflicts in `package.json` using strategy `--ours`\n\n    $ git log --oneline merge_master_to_develop\n    7cde612 Merge branch 'master' into merge_master_to_develop\n    0ea4d05 1.0.2\n    d94a1dc change in master: add dependencies\n    f2fefc6 2.0.1\n    b8c66c9 change in develop\n    263aa5f 2.0.0\n    386ae99 1.0.1\n    6160dea change in master\n    be4abab add git-resolve-conflict script\n    ...\n\n\nWe need to be cautious\n======================\n\nWe have changes in `master` that would be lost on merge if we did a brutal `git checkout --ours package.json`\n\n    $ git show master^\n    commit d94a1dc5ff0aba1c0d9c2a3dd8f9bec3147578d2\n    Author: jakub-g \u003cjakub.g.opensource@gmail.com\u003e\n    Date:   Wed Aug 24 14:13:16 2016 +0200\n\n        change in master: add dependencies\n\n    diff --git a/package.json b/package.json\n    index f709434..a609d8c 100644\n    --- a/package.json\n    +++ b/package.json\n    @@ -6,6 +6,10 @@\n       \"scripts\": {\n         \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n       },\n    +  \"dependencies\": {\n    +    \"foobar\": \"1.0.0\",\n    +    \"quux\": \"2.0.0\"\n    +  },\n       \"author\": \"\",\n       \"license\": \"ISC\"\n     }\n\n\nLet's merge\n===========\n\n    $ git checkout develop\n    Switched to branch 'develop'\n\n    $ git checkout -b merge_master_to_develop\n    Switched to a new branch 'merge_master_to_develop'\n\n    $ git merge master\n    Auto-merging package.json\n    CONFLICT (content): Merge conflict in package.json\n    Automatic merge failed; fix conflicts and then commit the result.\n\n    me@mymachine /d/git/merge-file-ours-poc (merge_master_to_develop *+|MERGING)\n    $ git diff\n    diff --cc package.json\n    index 75c469b,f709434..0000000\n    --- a/package.json\n    +++ b/package.json\n    @@@ -1,6 -1,6 +1,12 @@@\n      {\n        \"name\": \"merge-file-ours-poc\",\n    ++\u003c\u003c\u003c\u003c\u003c\u003c\u003c HEAD\n     +  \"version\": \"2.0.1\",\n    ++||||||| merged common ancestors\n    ++  \"version\": \"1.0.0\",\n    ++=======\n    +   \"version\": \"1.0.2\",\n    ++\u003e\u003e\u003e\u003e\u003e\u003e\u003e master\n        \"description\": \"merge-file-ours proof of concept\\r ================================\",\n        \"main\": \"index.js\",\n        \"scripts\": {\n\n    me@mymachine /d/git/merge-file-ours-poc (merge_master_to_develop *+|MERGING)\n    $ cat package.json\n    {\n      \"name\": \"merge-file-ours-poc\",\n    \u003c\u003c\u003c\u003c\u003c\u003c\u003c HEAD\n      \"version\": \"2.0.1\",\n    ||||||| merged common ancestors\n      \"version\": \"1.0.0\",\n    =======\n      \"version\": \"1.0.2\",\n    \u003e\u003e\u003e\u003e\u003e\u003e\u003e master\n      \"description\": \"merge-file-ours proof of concept\\r ================================\",\n      \"main\": \"index.js\",\n      \"scripts\": {\n        \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n      },\n      \"dependencies\": {\n        \"foobar\": \"1.0.0\",\n        \"quux\": \"2.0.0\"\n      },\n      \"author\": \"\",\n      \"license\": \"ISC\"\n    }\n\n`git-resolve-conflict` to the rescue\n====================================\n\n    ######################################################################################\n    ##          doing `git checkout --ours package.json` at this point is WRONG!        ##\n    ##                it would lose the changes in `master^` commit                     ##\n    ##                            we need something better                              ##\n    ######################################################################################\n\n\n    me@mymachine /d/gh/merge-file-ours-poc (merge_master_to_develop *+|MERGING)\n    $ source ./git-resolve-conflict.sh\n\n    $ git-resolve-conflict\n    Usage:   git-resolve-conflict \u003cstrategy\u003e \u003cfile\u003e\n\n    Example: git-resolve-conflict --ours package.json\n    Example: git-resolve-conflict --union package.json\n    Example: git-resolve-conflict --theirs package.json\n\n    $ git-resolve-conflict --ours package.json\n\n    $ git diff\n\n    $ git diff --cached\n    diff --git a/added-in-master.txt b/added-in-master.txt\n    new file mode 100644\n    index 0000000..9cef8af\n    --- /dev/null\n    +++ b/added-in-master.txt\n    @@ -0,0 +1 @@\n    +added in master\n    diff --git a/package.json b/package.json\n    index 75c469b..03f513b 100644\n    --- a/package.json\n    +++ b/package.json\n    @@ -6,6 +6,10 @@\n       \"scripts\": {\n         \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n       },\n    +  \"dependencies\": {\n    +    \"foobar\": \"1.0.0\",\n    +    \"quux\": \"2.0.0\"\n    +  },\n       \"author\": \"\",\n       \"license\": \"ISC\"\n     }\n\n    $ git status\n    On branch merge_master_to_develop\n    All conflicts fixed but you are still merging.\n      (use \"git commit\" to conclude merge)\n\n    Changes to be committed:\n\n            new file:   added-in-master.txt\n            modified:   package.json\n\n    $ git commit\n    [merge_master_to_develop aed5278] Merge branch 'master' into merge_master_to_develop\n\nFinal situation\n============================================\n\n    me@mymachine /d/gh/merge-file-ours-poc (merge_master_to_develop)\n    $ cat package.json\n    {\n      \"name\": \"merge-file-ours-poc\",\n      \"version\": \"2.0.1\",\n      \"description\": \"merge-file-ours proof of concept\\r ================================\",\n      \"main\": \"index.js\",\n      \"scripts\": {\n        \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n      },\n      \"dependencies\": {\n        \"foobar\": \"1.0.0\",\n        \"quux\": \"2.0.0\"\n      },\n      \"author\": \"\",\n      \"license\": \"ISC\"\n    }\n\nEverything is fine, merge resolved correctly!\n\n- version is 2.0.1 (taken from `develop`)\n- dependencies are not lost (taken from `master`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakub-g%2Fgit-resolve-conflict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakub-g%2Fgit-resolve-conflict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakub-g%2Fgit-resolve-conflict/lists"}