Reputation: 2316
Consider the following scenario
There are two files
FileA
FileB
I have made changes to FileB. In the remote repository, Some one has made changes to the FileA and FileB. I pull in from the upstream and there is merge conflict in FileA.
I fix the merge conflict, now when I check git status
, I see the FileA staged and FileB as modified.
on branch master
Your branch is ahead of origin/master by 1 commit.
You have unmerged paths. (fix conflicts and run "git commit").
Changes to be committed:
modified: FileA
Unmerged paths: both modified FileB
Here you can see status of FileA is in staged state on merge fail. But I didnt modify it. Now when I stage resolved conflict file FileB and commit, FileA will be there with the commit but the FileA is actually not touched by me.
It becomes so difficult when there are hundreds of files all appearing in the commit history on merge fail though it was not actually modified by me.
How can I deal with this situation in Git.
Any help is greatly appreciated. Thanks!
Upvotes: 0
Views: 135
Reputation: 7867
Git does not manage files alone, but branches containing files, meaning you don't push changes on a file, you actually push your local branch state everytime.
In your case, if FileA
was not included in your commit, then pushing your branch would override FileA
on the remote with the one you had on your local branch, and the changes on FileA
would be lost.
You can read more about branches on Git here.
Upvotes: 0
Reputation: 2883
While resolving a merge conflict git will provide you with information to manually resolve the conflicts. In your case git informs you that remote master also contains a change in FileA
, this may be helpfull if the changes in remote FileB
depends on changes in FileA
, a change that you may need to take in account when manually resolving the conflict in FileB
.
You need to stage both FileA
and FileB
after you have resolved the conflict. If FileA
is staged without any changes it will not be a part of the merge commit (the merge commit will not be included in the commit history for FileA
)
NOTE: if you have a LF/CRLF conversion applied to your files they might contain whitespace changes when staged and therefor they will be included in the merge commit.
You might update you local repo by rebasing the changes onto your branch, but you may still need to keep track of any dependent changes introduced by this update.
Upvotes: 1