Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:38:20+00:00 2026-05-29T22:38:20+00:00

Let’s say I have some code that is ordered, but the ordering is not

  • 0

Let’s say I have some code that is ordered, but the ordering is not a technical requirement.

apple
kiwi
strawberry

And then I have two topics that I want to merge in, whose diffs look like:

TOPIC BRANCH: orange
  kiwi
+ orange
  strawberry

And also

TOPIC BRANCH: pear
  kiwi
+ pear
  strawberry

Is there a way for these two patches to get resolved automatically? It seems to me like it is a merge conflict since they compete for the same new line. A solution I’ve come up with is to reorder one of the changes since the sort order is only a soft requirement (where fruits are actually function definitions).

 TOPIC BRANCH: pear'
   apple
 + pear
   kiwi

So now we can merge orange and pear' together to form:

 _ apple
 p pear
 _ kiwi
 o orange
 _ strawberry

Are there other ways to resolve this such that the ordering can be kept? I also thought of pear having to downstream from orange such that orange always gets priority and there wouldn’t be a merge conflict anymore. But this is a false dependency since orange and pear are two separate feature branches.

One could be mainlined into the trunk before the other but that doesn’t address integration branches.

Edit: It just dawned at me for two hunks that could be kept (additions only I guess?) there could be two merge strategies called “me first” and “you first” such that an ambiguous ordering could be resolved non-interactively between two branches.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:38:21+00:00Added an answer on May 29, 2026 at 10:38 pm

    The basic approach is to define a custom merge tool and then use the git attributes feature to tell git to use that custom merge tool for those files.

    Example:

    1. create a test repository:

      $ git init t
      $ cd t
      
    2. define a custom merge tool called mymerge:

      $ git config merge.mymerge.name "my custom merge tool"
      $ git config merge.mymerge.driver "cat '%A' '%B'|sort -u >'%A'.tmp && mv '%A'.tmp '%A'"
      

      The above merge tool concatenates the files, sorts the resulting lines, and then removes duplicate lines. If you don’t want to change the order, replace the above command with a custom script that does what you want. See git help attributes for more information.

    3. tell git that you want to use mymerge when merging any file named foo.txt in the repository:

      $ echo "foo.txt merge=mymerge" >.gitattributes
      $ git add .gitattributes
      $ git commit -m "tell git to use the mymerge merge tool for foo.txt"
      
    4. make some test data on three branches:

      $ printf 'apple\nkiwi\nstrawberry\n' >foo.txt
      $ git add foo.txt
      $ git commit -m "common ancestor version of foo.txt"
      $ git checkout -b orange
      $ printf 'apple\nkiwi\norange\nstrawberry\n' >foo.txt
      $ git commit -a -m "add orange"
      $ git checkout -b pear master
      $ printf 'apple\nkiwi\npear\nstrawberry\n' >foo.txt
      $ git commit -a -m "add pear"
      
    5. merge the branches (note no conflicts!):

      $ git checkout master
      $ git merge orange
      $ git merge pear
      
    6. profit!

      $ cat foo.txt
      apple
      kiwi
      orange
      pear
      strawberry
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say i have this block of code, <div id=id1> This is some text
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say I have the string: hello world; some random text; foo; How could
Let's say that I have a set of relations that looks like this: relations
Let's say that I have a binary that I am building, and I include
Let's say that I have classes like this: public class Parent { public int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.