Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge conflict resolution shows staged changes which I didn't do

Tags:

git

Suppose following scenario.

  1. I clone a central git repo and checkout master branch.
  2. I do some changes in master branch in my local repo and commit.
  3. Other people do changes in master branch, commit and push to the central repo
  4. I try to pull master branch of central repo to mine.
  5. Merge conflict occurs.

Then, if I issue git status command, I see that a lot of changes (which I think were done by other people in step 3) which I didn't do are automatically staged for next merge commit which I am going to do after I resolve conflicts.

My question is, after conflict resolving and committing, does above mentioned changes which were staged but not done by me go to the repo as if they were done by me?

like image 772
Lahiru Chandima Avatar asked Mar 17 '15 16:03

Lahiru Chandima


People also ask

Why do I keep getting merge conflicts?

Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. You must resolve all merge conflicts before you can merge a pull request on GitHub.

What happens if you get a conflict during a merge?

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.


2 Answers

Every time you do a merge, a commit is created . Doing pull is effectively fetch and merge operation (unless you are fast forwarding).

When a merge is successful without any conflicts, you see a direct commit (given you are not fast forwarding). But when a coflict occurs, git leaves the files in coflict in a conflicted state. All other files which are merged succcessfully are placed in staged area. So when you finish your conflict, you can commit all the files together.

This commit is marked as a merge commit and other person reading the history in future should make out that this commit was caused by the merge and not for changes made by you.

like image 123
Vishwanath Avatar answered Nov 15 '22 04:11

Vishwanath


This normally happens if you haven't disabled some settings in your git config

The autocrlf option when this option is enabled and you pull something your line endings will be changed (if they are different) and your files are modified.

autocrlf = false
# or with this
git config --global core.autocrlf true

The next one is the filemode here its the same

filemode = false

Normally that are the problems. You can set these options in your git config file

.git/config
like image 25
René Höhle Avatar answered Nov 15 '22 05:11

René Höhle