Git content

Git is a common version management tool

Initialize Git

When using Git for the first time, you need to configure a user name and email address for Git. You can use github or your own git Lab repository account

Git config --global user.email git config --global user.emailCopy the code

After viewing all the configuration information, you can see the user.name and user.email configurations

git config -l
Copy the code

Second, the use of

1. Pull items

Git clone 'XXXX'Copy the code

2. Create branches

Look at all branches

git branch -a
Copy the code

Create your own branch

Git Branch Branch nameCopy the code

Switch to the branch you created

Git Checkout is the branch you want to switch toCopy the code

The above two instructions can be combined into the following one,Create and switch to the branch

Git checkout -b branch nameCopy the code

View your current branch

git branch
Copy the code

Commit code to cache

git add .
Copy the code

4. Comments for code submission

Feat: New function

Upd: modify

Del: delete

Fix: Fixes bugs

Test: unit test

Perf: Performance optimization

Docs: Updates the document

Style: style changes

Refactor: Function refactoring

Revert: Rolls back an earlier submission

Package: Creates a package

Git commit -m "git commit -m"Copy the code

5. Code submission

Git push origin commit branch nameCopy the code

Three, remote operation instructions

1. Display all remote warehouses

git remote -v
Copy the code

2. Get changes in the remote warehouse

Git merge Git merge Git Merge Git merge

Git fetch origin branch nameCopy the code

3. Merge the code

Git merge branch nameCopy the code

4. Pull the remote repository code and merge with the local branch

Git fetch is a combination of git merge and Git fetch. Git merge is a combination of git fetch and Git merge. Git merge is a combination of git fetch and Git merge

git pull
Copy the code

5. Forcibly push the current branch to the remote repository, even if there are conflicts

git push --force
Copy the code

Other instructions

1. Display the changed file status

git status
Copy the code

2. Display the current branch version history

git log
Copy the code

3. Display the submitted history and changed files

git log --stat
Copy the code

4. Display the past 5(n) commits

git log -5 --pretty --oneline
Copy the code

5. Display all users of the warehouse who have submitted codes, and rank them according to The Times of submission

git shortlog -sn
Copy the code

6. Show the number of lines of file changes and code changes committed today

git diff --shortstat "@{0 day ago}"
Copy the code

5. Code rollback

Before rolling back the code, we first use git log to view our code commit record, and then after viewing the code commit record we can roll back according to the version

1. Roll back to the previous version

git reset --hard HEAD^
Copy the code

2. Roll back to before n commits

git reset --hard HEAD~n
Copy the code

3. Roll back to the specified committed version

Git reset - hard commit # the hash value of the hash value is to input the git log can see after a string of characters #, for example the git reset - 92 f1eb5aa5db9e04753e75a37ffd76f793cb281e hardCopy the code

After the rollback, it is possible that the code will fail to commit and must be forced to remote

git push origin HEAD --force
Copy the code