1

Let me present a scenario - I'm working on a repo, under my_branch branch, and I need to merge changes from other_branch to my branch.

I ran the command: git merge origin/feature/other_branch

Here is a sample git status after running this command:

$ git status
On branch feature/my_branch
Your branch is up-to-date with 'origin/feature/my_branch'.
You have unmerged paths.
  (fix conflicts and run "git commit")

Changes to be committed:

        modified:   file1
        modified:   file2

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   file3
        both modified:   file4

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   file5
        modified:   file6        

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        file7
        file8

As you can see, changes to file1 and file2 have been accepted from other_branch and have been staged for commit.

I've encountered a merge-conflict in file3 and file4, which I've fixed manually on my editor.

I've made some changes to file5 and file6, but I'm not willing to commit those yet...

I've added file7 and file8 to the workspace, but I'm not willing to commit those either.

To add the conflicted files to stage, I need to run:

git add file1
git add file2

Is there some flag in git add, using which I can only the files in both modified state, whilst ignoring modified and unstaged files ?

Thanks

Saransh Kejriwal
  • 2,467
  • 5
  • 15
  • 39
  • I don't know of this option, but you can always open the files in conflict and look at the merge markers. – Tim Biegeleisen Jul 10 '18 at 06:55
  • Have you tried looking in the [git documentation] (https://git-scm.com/docs/git-add) for such a flag? – T A Jul 10 '18 at 06:57
  • No, currently there is no such "special add". You should force your self not doing "developent" while merging is still in progress. – Timothy Truckle Jul 10 '18 at 07:18

1 Answers1

2

git add itself has no such flag.

But it can take as parameters a list of files.
And you can list unmerged files:

git diff --name-only --diff-filter=U

So, something like this could work (using this to bring all files in one line):

git add $(git diff --name-only --diff-filter=U | xargs)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250