Common commands such as Git branches that you deserve to master (continuous update)

1. Local

1.1 Create a branch

git branch name

E.g:

Insert picture description here

1.2 Switch branches

git checkout name

or

git switch name

E.g:

Insert picture description here

1.3 Create + switch branches

git checkout -b name

or

git switch -c name

E.g:

Insert picture description here

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

Insert picture description here

1.5 View branch

$ git branch 

Insert picture description here

1.6 delete branch

git branch -d name

Insert picture description here

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:
Insert picture description here

2.2 Step 2: Submit changes in the branch

 git commit -m "描述内容"

E.g:
Insert picture description here

2.3 Step 3: Submit to the remote

git push -u origin 分支name

Insert picture description here
In fact, the main partition is the same, for example, I am changing a picture
Insert picture description here

Three, view local and remote warehouses

3.1 View all remote branches

git branch -r

E.g:
Insert picture description here

3.2 View all local branches and remote branches

git branch -a

Insert picture description here

Fourth, version rollback

Use the git logcommand 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:
Insert picture description here
restore to the historical version

git reset --hard 版本号

E.g
Insert picture description here

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

Guess you like

Origin blog.csdn.net/hanhanwanghaha/article/details/111301113