git code fallback method

1 Determine the branch to be rolled back

For example dev branch; then switch to dev branch

2 Using the log command

git log

Check the submission record (because you have switched to dev, so you are looking at the submission record of dev), find the commit position that needs to be rolled back, and record the commit number, for example:

commit 96f6ec9bf41fe0e425f8495d46a52b8f990facd3

<Note, the rollback to this commit location includes the code submitted by this commit; if you don’t want the code submitted by this commit, then roll back to the last commit location>

3 Execute the rollback command

Will roll back the local code to the state of this commit (including this commit):

git reset --hard 96f6ec9bf41fe0e425f8495d46a52b8f990facd3

4 Execute the command to force push the local code to the remote

git push origin dev  --force

illustrate:

●If you do not use the force command, you cannot push to the remote, and there will be conflicts.
(Of course there will be conflicts. After the rollback code, the current local version is inconsistent with the remote version. For example, the local version is v0.1, and the remote version is v0.2; if you want the remote version to also roll back to v0.1, you can only use the force command)

●Note that after the push, the remote code submission history will be the same as the local one (meaning that the v0.2 code submission record is gone; if there is still required code in the v0. sort it out first, and then execute the push rollback command)

●origin means the remote url (the URL of .git), which is configured before

●dev means the remote dev branch

●The meaning of the whole command is to force push the code of the local current branch to the remote dev branch (ignore conflicts and directly overwrite)
 

Guess you like

Origin blog.csdn.net/weixin_39910711/article/details/128822788