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 9075881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:58:28+00:00 2026-06-16T18:58:28+00:00

Let’s suppose that I get a merge conflict on foo/bar.txt when running this: $

  • 0

Let’s suppose that I get a merge conflict on foo/bar.txt when running this:

$ git checkout A
$ git merge B

I’d like to automatically resolve the conflict by taking foo/bar.txt from branch A. (I know what I’m doing, and I do need this. The version in branch B is wrong, and I don’t care about losing changes in the working tree in this case.) It seems that I can do it by running these commands:

$ git reset    foo/bar.txt
$ git checkout foo/bar.txt

Is there a simpler, single-command solution?

Unfortunately these commands change foo/bar.txt even if there is no conflict, and I don’t want that. If there is no conflict, I want want to keep foo/bar.txt in whatever state git merge B has left it.

So I need a Unix shell command, which would detect if there is a conflict in foo/bar.txt, and if there is, it would resolve the conflict by taking the version of foo/bar.txt from the current branch. It wouldn’t do anything else, i.e. it wouldn’t modify other files, it wouldn’t commit the changes, and it wouldn’t change foo/bar.txt if there is no conflict in that file.

  • 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-06-16T18:58:29+00:00Added an answer on June 16, 2026 at 6:58 pm

    If you want to do it as a one-off, the single-line command is:

    $ git checkout --ours foo/bar.txt  # <-- resets it only if the merge found conflicts in this file
    $ git checkout HEAD -- foo/bar.txt # <-- resets it to that specific version no matter what
    

    To configure git’s merge to permanently ignore all upstream changes to a locally-changed file:

    $ git config merge.pin.driver true
    $ echo foo/bar.txt merge=pin >> .git/info/attributes
    

    (true above is just the unix true command, its success says it made the local version look right, in this case by doing nothing to it. You can of course get more sophisticated with your merge commands.)

    I think you don’t want merge --strategy=ours or --strategy-option=ours, those apply to entire merges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have pseudocode like this: main() { BOOL b = get_bool_from_environment(); //get
Let's say that I have classes like this: public class Parent { public int
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have an actor like this (Using Akka 2.1 with Scala 2.10):
Let me preface this question with the fact that I am very new to
Let me frame it this way.. Say I have an application server running on
Let suppose I have this class diagram in UML: How can I do, in
Let's say I've got a collection of 10 million documents that look something like
Let say you have an XML like this: <?xml version=1.0 encoding=utf-8?> <Class HashCode=307960707> <Person>

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.