Bird
0
0

During a complex merge, you want to script resolving all conflicts by always choosing the current branch's version. Which command sequence achieves this?

hard📝 Application Q9 of 15
Git - Cherry-Pick and Advanced Merging
During a complex merge, you want to script resolving all conflicts by always choosing the current branch's version. Which command sequence achieves this?
Agit reset --merge
Bgit ls-files -u | cut -f 2 | sort -u | xargs git checkout --theirs && git add .
Cgit merge --strategy=ours
Dgit ls-files -u | cut -f 2 | sort -u | xargs git checkout --ours && git add .
Step-by-Step Solution
Solution:
  1. Step 1: List conflicted files

    'git ls-files -u' lists unmerged files; extracting filenames with 'cut' and 'sort -u' gets unique conflicted files.
  2. Step 2: Checkout 'ours' version for each conflicted file and stage

    Using 'xargs git checkout --ours' replaces each file with current branch version, then 'git add .' stages all.
  3. Final Answer:

    git ls-files -u | cut -f 2 | sort -u | xargs git checkout --ours && git add . -> Option D
  4. Quick Check:

    Script to keep ours = list conflicts + checkout --ours + add [OK]
Quick Trick: Script conflicts: list files, checkout --ours, then add [OK]
Common Mistakes:
  • Using --theirs instead of --ours
  • Not listing conflicted files correctly
  • Forgetting to add after checkout

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Git Quizzes