Super detailed Git study notes

1. Configure environment variables

1. Set user information

git config --global user.name "xxx": set username

git config --global user.email "xxx": set user mailbox

2. View configuration user information

git config –list

git config user.name

2. Get the Git repository

1. git init: Initialize a repository locally

2. git clone remote warehouse address: clone remote warehouse

3. There are two states of files in the Git working directory

1. untracked: not tracked (not included in version control)

2. tracked: tracked (incorporated into version control) Unmodified: unmodified state

Modified: Modified state Staged: Staged state

Fourth, the local warehouse operation

1. git status: View file status -s: Make the output information more concise

2. git add: Change the file from untracked state to tracked state.: All files

3. git reset (HEAD): restore the file from the tracked state to the untracked state

4. git commit: Submit to the local warehouse -m: Enter log information in string format -a: Add to the staging area before submitting

5. git rm: delete the workspace file and upload it to the staging area

6. git log: view log q: exit

5. Remote warehouse operation

1. git remote: view the remote warehouse (the default is origin) -v: detailed: show origin: super detailed

2. git remote add: Add a remote repository

3. git remote rm: remove the remote warehouse

4. git fetch: grab the latest version of the remote warehouse (it will not automatically merge)

5. git merge (origin/master): extract data from the objects folder in .git to the local warehouse

6. git pull (origin master): Pull the latest version of the remote warehouse (automatic merge) Note: Non-clone remote warehouses and create local warehouses containing files --allow-unrelated-histories can be solved

7. git push origin master: push the local warehouse to the remote warehouse

8. git push -u –force origin master: forcibly replace the contents of the remote warehouse

6. Git branch

1. git branch: View local warehouse branches -r: View remote warehouse branches -a: View all branches

2. git branch branch name: create a local branch

3. git checkout branch name: switch branches git checkout -b branch name: create and switch branches

4. git merge branch name: merge other branches under this branch. When two branches have the same file name but different content, they need to be processed manually and solved and submitted using the add command and commit

5. git branch -d branch name: delete local branch -D: force delete

6. git push origin -d branch name: delete remote branch

7. Git tags

1. git tag: View tags

2. git tag tag name: create a tag

3. git show tag name: View the specified tag in detail

4. git push origin Tag name: push the tag to the remote warehouse

5. git checkout -b branch name label name: check out the branch (create a new branch according to the label status)

6. git tag -d tag name: delete local tags

7. git push origin :refs/tags/tag name: delete remote tags

8. git rm -r --cached : use this command when .gitignore is invalid

9. ssh-keygen -t rsa: generate public and private keys

10. git checkout - : restore the staging area files to the workspace (when deleting local files)

11. git reset --hard: go back to the specified version

git reset --hard HEAD^: go back to the previous version

12. git reflog: View historical and future versions (when deleting local and repository files)

This blog is a note taken by the blogger when he was learning Git. Hope it can help you

Guess you like

Origin blog.csdn.net/qq_45821420/article/details/108618028