Some of the most common Git commands
Configure Git
$git config --global user.name "git username "$git config --global user.email "git username" $git config --global user.email "git username --unset alias.xxx $ git config --global --unset user.xxxCopy the code
Look at the Git
$git reflog $git reflog $git reflog $git reflog $git reflog $git reflog $git reflog Git # git # git # git # gitCopy the code
Git Common Commands
$git add fileName OR git add * # commit to local repository $git commit -m "Commit note" # $git pull origin branchName $git pull origin branchName $git pull origin branchName $git pull origin branchName $git pull origin branchName $git pull origin branchName $git branch $git branch $git branch $git branch $git branch $git branch $git branch $git branch $git stash pop $git stash pop $git push --set-upstream Origin $git push --set-upstream origin Branch_name $git checkout --track origin/branch_name $git checkout --track origin/20200710-pre $git push origin branch__name $git push origin branch__nameCopy the code
Reference: Git experience and FAQ
Rolling back some common commands The git reset command is used to roll back the version. You can specify a version to be rolled back.
Syntax format: git reset [- soft | – mixed | — hard] [HEAD]
-
The –soft parameter is used to roll back to a version
git reset --soft HEAD
The sample
$git reset --soft HEAD~3Copy the code
-
This parameter is used to reset the staging file to the same value as the previous commit, and the contents of the workspace file remain the same.
git reset [HEAD]
The sample
$git reset HEAD^ # $git reset HEAD^ # $git reset HEAD^ # $git reset HEAD^ # $git reset HEAD^ # $git reset HEAD^ # $git reset HEAD^ # $git reset HEAD^ # $git reset HEAD^ #Copy the code
-
The –hard argument uncommits all uncommitted changes in the workspace, returns both the staging area and the workspace to the last version, and deletes all previous information commits
git reset --hard HEAD
The sample
$git reset - hard HEAD~3 # To roll back to the previous version $git reset - hard bae128 # to roll back to the previous version. $git reset --hard origin/master #Copy the code
Pay attention to
Use the — hard parameter with caution. It deletes all information up to the fallback point. HEAD note:
- HEAD Indicates the current version
- HEAD^ Previous version
- HEAD^^ The previous version
And so on…
- You can use the ~ number
- HEAD~0 indicates the current version
- HEAD~1 Previous version
- HEAD^2 is a previous version
And so on…
Git graphical operations
This is a good thing for developers. Many git commands are easy to forget, and graphical operations can save the trouble of writing them. Simple, convenient and fast.
Reference link: Gitlab – Web interface Revert rollback operation