'git pull' brings foreign commits to my staging area during merge conflict

So, I often came across this unpleasant problem and tried to search for any solutions on the Internet, but I'm not sure if this is the expected git behavior or not.

Whenever I have several local commits and I do git pull , git transfers all other peoples to my intermediate area in case I have a merge conflict. Now, although the conflict is in one file, I don’t understand why git leads to conflicting conflicts of other people in my intermediate area, asking me to transfer them as if they were changes / commits made by me.

Recently, I had the same behavior on a colleague's laptop, and we excluded all files that were not added by a colleague before committing, and then transferred a single file that contradicted each other. And what happened was completely unexpected. git seems to have deleted all these files, unzipped all the changes as if our team had changed them.

However, the strangest thing is that we looked at Stash (we use Stash to manage the central repo), and I did not see that these files were canceled by our commit to Stash.

I do not understand how this happened. Any plausible explanation? In addition, I saw how Stast is very strange at times. It seems unreliable. It will not show any changes between the two commits, but there are still changes. I have no idea how this happens, but has anyone else experienced these problems?

Update . I realized this later that Steish was not strange, just a little unintuitive. When merging, he showed changes based on two different parents. And there was a small drop-down menu that would allow you to change the parent to see the corresponding changes. I thought it would be nice to update it here so that people do not mislead ideas.

+6
source share
2 answers

The floor files you see are the result of all the changes between the last synchronization of your local branch with the remote branch (I assume the wizard, as you don't mention it).

Git pull “pulled” the changes since the last pull, then tries to merge this local copy of the remote branch into your local branch. Then he got into a conflict in one of the modified files.

Therefore, he should stop in the middle of the merge to ask how to resolve the conflict in one file.

Thus, other files are ready to be merged, delivered and would be merged automatically if there were no other conflicts.

To complete the automatic merge, you need to: a) resolve the conflict, and then b) click commit to complete the merging of other people with the changes in your local branch. (Some graphical interfaces automate the step of completing the commit after clicking "I finished the resolution")

You will also notice that in the commit window of your GUI there is a ready merge message for the pending commit? He will say something like "a merger of origin / x into x ... Conflicts: y". After all the modified files can be added to the scene, you are ready to complete this automatic commit, which has been paused.

So this sounds like the expected behavior for me, but you just see the “inside” of one of the internal git processes.

Stamping should not be necessary or involved here. Although some GUIs do autosave, git itself does not use embossing during pull.

Note: you should not have any modified files locally when you do pull. (i.e., doing everything clean before doing any operations with the branch is good practice). The GUI utility to clean up your modified files is when autoload is useful, but it still has its difficulties in case of conflicts. those. you need to resolve conflicts, and then remember to pop up later. If you rely too much on automation, it gets confusing when you need to complete an automatic process that you don't know about! Therefore, I recommend that you always keep your working directory clean.

+7
source

The default behavior of git pull is to fetch and then a merge . Merging is factual, new, fixed; this is usually resolved automatically, so you do not see any incremental changes. However, in the event of a conflict, the commit cannot be executed automatically, therefore, visible phased changes.

+1
source

Source: https://habr.com/ru/post/984715/


All Articles