Conflict resolution or conflict avoidance in GIT?

2020-07-18 11:19发布

问题:

Questions: How are several people meant to work with GIT? Is update-commit usual as in SVN or is merge the default? When merging, who should appear as the author of the merging commit?

A lot of background information: I am writing a paper on LaTeX with another guy and we are using GIT for the version control.

From the start we decided we both would work on the master branch, because we are anyway only two people.

I've done a number of commits. Then he did a commit over an old version and merged my last version and the most recent one (after his commit). This is easier to see with a picture:

To me it's weird to make the merge that way, if I'm not mistaken he should have pulled first and then committed, merge should be done between two different branches.

Weirdest of everything, my commits are not deleted at any point, but the contents appear as new in the latest commit and he appears as the author. This looks like a bug, but to say the truth I don't really understand what is going on here.

So the questions are:

Is that a bug?

Should we be using branches to work separately? I could be ignoring his commits if he doesn't push them to the server anyway.

Did he use the system properly or should he have done a pull before committing as in SVN (update -> commit)?

Last, I did a branch, a commit and a merge (that's not in the picture, yet), and probably the same thing is going to happen again because now the master is updated and he is probably going to ignore those updates, commit, then merge as the author.

That doesn't look right to me, but I don't know whether it is right or not.

IMHO: merge should be done locally, before pushing the updates to the shared repository, as in an update-commit fashion.

回答1:

Should we be using branches to work separately?

Yes: he should have done a git pull --rebase (for a branch not yet pushed), before pushing his changes, at which point you would have been able to merge his branch as a simple fast-forward merge.
See also merge vs. rebase and a similar blog post.

(from Git Is Your Friend not a Foe Vol. 4: Rebasing)

More generally, yes, merge locally before pushing.