It’s not uncommon to encounter requirements that involve multiple people collaborating on a common branch, but you’ll always see weird Git operations like merge (🤏), fallback, and push (black question.jpg).
Therefore, I would like to share with you my method, which is relatively clean and can ensure that future generations use silky, friendly to those who pursue smooth Git nodes, and can be assured to eat it.
- Every time your code is committed and before you change it again, remember first
git pull
- Local code changes to submit, 🚶 old trilogy:
git add .
git commit -m 'feat: xxx'
git push
- If there is no conflict above, then I write this article in vain 🙄️
- Is there a conflict? I told you there was. Here comes the essence:
git log
Get the current commit ID that you just committedgit reset --hard HEAD^
(Hard means to force a rollback, HEAD followed by ^ or ~ means to rollback a version, i.e. a commit.)git pull
The latest code on the pull line (this is a successful pull if there is no rollback of the common branch on the line that causes the node to change, otherwise the pull might conflict)- If there is a conflict, execute
git reset --hard <commit id>
orGit reset - hard HEAD ~ < n >
(n stands for any number, you can also use HEAD^^^^^, a few ^ to indicate a few steps back) - To perform
git pull
- If the conflict persists, go back to step I until there is no conflict
- If there is a conflict, execute
git cherry-pick <commit id>
This can be used if the COMMIT ID is lostgit reflog
And then find the missing ID hash based on the commit message)- If there is a conflict, modify it before performing the commit trilogy:
git add .
git commit -m 'feat: xxx'
git push
- If there is no conflict, execute it directly
git push
- If there is a conflict, modify it before performing the commit trilogy:
Hope to you can some help (did not help close my PI matter 😳)