[Git learning] version rollback and branch

Simple use of git local

Undo uncommitted changes

git checkout -- 文件名 

Applicable to unadded changes, equivalent to directly reverting to the state of the previous submission

Cancel add

git reset HEAD 文件名

Roll back the file to the unadded state

View commit history

git log

Back to the previous version

$ git reset --hard HEAD^

The last version was HEAD ^^

When multiple, it can be written as HEAD ~ number

Submit record

git reflog

Back by commit id

git reset --hard commit id

The commit id can be found by git log (view the commit record) or git reflog (view the history of the command)

It is not necessary to write the full version number, the first few digits are enough, and Git will automatically find it. Of course, you can't just write the first one or two, because Git may find multiple version numbers, and you can't determine which one.

Different branches

Create a branch named new

git branch new

Go to new branch

git checkout new

Back to master branch

git checkout master

Merge branch

In the master branch

git merge new

If there is no conflict, it will automatically merge

If there is a conflict, you need to make your own choice

Published 163 original articles · praised 18 · visits 7683

Guess you like

Origin blog.csdn.net/xcdq_aaa/article/details/105380228