SourceTree reset commit, merge, undo, rollback

  • SourceTree resets the current branch to this commit

scenes to be used:

  1. The revisions that have been submitted but not pushed are revoked, and I want to revoke all the wrong revisions of a certain time

  1. The current release code has a bug and needs to be switched to the last submitted release version

HEAD in Git explained

# Remake the staging area with the latest commit

git reset HEAD -- filename

# Remake the staging area and workspace with the latest commit

git reset --hard HEAD

# Roll back the commit log once to the staging area and the code in the work area remains unchanged

git reset --soft HEAD~1

  • Merge mode description:

soft merge

Soft merging refers to rolling back the submission to the specified submission location, but during this process, the modified files will be temporarily stored in the temporary storage area

hybrid merger

Mixed merge refers to rolling back the submission to the specified location, but in this process, the modified file will not be temporarily stored in the temporary storage area, but the modified file will be stored in the untemporary file area

forced merger

Forced merging refers to rolling back the submission to the specified location, but all previously modified files will be directly discarded during this process (so you need to think carefully when choosing this kind of merging to avoid unnecessary troubles).

  1. forced merger

After the execution is completed, it will prompt that there is a new update to be pulled. Do not pull it. After pulling it, the previous one will be pulled locally. You should execute commit, but it cannot be executed by sourceTree. At this time, use the terminal.

Open the terminal, cd to the project directory, and execute git push -f on the current branch

After the forced push, the Git submission will discard the submission record before the reset (44444 submission will be flushed, and the latest submission will become 333 submission)

  • how to undo

After the strong merge (there will be a prompt of xx versions behind, because the code has been reset to this submission, and there will be an update prompt on the pull button) if you want to cancel this merge, just click pull and confirm

  1. hybrid merger

  1. soft merge

Also talk about the difference between rollback and reset submission:

1. Rollback - refers to when the changed code is submitted to the local warehouse, but not pushed to the remote warehouse

也就是说刚刚提交代码,没有推送,这时候你发现提交错了,只需要选择本地分支你刚提交的节点上,右击回滚一下即可,这时候本地分支会出现“Revert”的字样,推送按钮会出现提示推送的角标,这时候你可以直接推送一下,远端也不会有变化,只不过是推送一些日志记录或者其他与代码无关的,或者也可以提交好正确的代码后,一起推送。

还有一种情况就是回滚后发现没有错误...(贼尬)...这时候刚写的代码已经没了...那就索性再回滚一次,也就是说撤销刚才的回滚操作,这时候本地分支节点上会出现“Revert 'Revert '”的字样...推送按钮也会出现提示推送的角标,这时候可以仿照上一步后半部分操作。

2、重置当前分支到此次提交——是指将改动的代码提交到本地仓库后,并已推送到远端仓库的时候

Guess you like

Origin blog.csdn.net/RreamigOfGirls/article/details/129396530