Git branch
1. Local
1.1 Create a branch
git branch name
E.g:
1.2 Switch branches
git checkout name
or
git switch name
E.g:
1.3 Create + switch branches
git checkout -b name
or
git switch -c name
E.g:
1.4 Merge a branch to the current branch
This means to merge the name branch with the current branch (note: the name branch is not affected, the current branch is changed)
git merge name
1.5 View branch
$ git branch
1.6 delete branch
git branch -d name
2. Submit to the remote end (three steps)
2.1 The first step: add new changes to the branch
A dot means submit all uncommitted files under the current workspace folder to the temporary storage area. If it is a specific file, add the name directly after git add
git add .
E.g:
2.2 Step 2: Submit changes in the branch
git commit -m "描述内容"
E.g:
2.3 Step 3: Submit to the remote
git push -u origin 分支name
In fact, the main partition is the same, for example, I am changing a picture
Three, view local and remote warehouses
3.1 View all remote branches
git branch -r
E.g:
3.2 View all local branches and remote branches
git branch -a
Fourth, version rollback
Use the git log
command to view all historical versions and get the id of a certain historical version (see the long string after the commit in the picture below)
For example:
restore to the historical version
git reset --hard 版本号
E.g
Five, other commonly used commands
5.1 View the status of the repository
git status
5.2 Submit the modified file test.txt of the workspace to the temporary storage area of the version library (different from the previous git add .)
git add test.txt
5.3 View version information
detailed
git log
simplified
git log --pretty=oneline
5.4 Store to remote
(The following code is required for the first upload to the remote end)
git remote add origin git 网址
(The following code is unnecessary for the second or later submission)
git push -u origin master
https://blog.csdn.net/hanhanwanghaha Welcome to follow this super invincible and cute duck. If you have any questions, you can leave a private message and you will reply if you see it!
Creation is not easy, if reprinted, please indicate the source