Why does Git sometimes add a commit when it executes a pull command?
- Recently, when I was developing a project, I ran the pull command to pull the remote repository code, and somehow a merge commit message was always generated locally. I also compared the content before and after the merge, and found that there was no conflict and no special treatment was required.
- Git fetch == git fetch + git merge
- This means that when you pull code it automatically merges into your current local branch
How do you reproduce this problem?
- Open a demo, put it in a remote repository, and pull two copies of code AB locally to simulate a multiplayer environment.
- First ab pulls the latest code, which is synchronized,
- A generates a new commit locally, and B also generates a new commit.
- B Uses the pull command to find that a new merge commit is created on the local device. No conflict occurs. If a merge commit is pushed, another merge commit is created on the remote device
Summary: This is where auto-merge occurs when your local and remote branches are out of sync
How to solve it?
Git pull –rebase — git pull –rebase — git pull –rebase
Git merge merge Git merge merge Git merge merge Git merge merge Git merge