This is the 8th day of my participation in the More text Challenge. For details, see more text Challenge

Git is a distributed version control system that is heavily used by almost every software development team thanks to efficient, collaborative, and fast project code management features. This is an introduction to git commands, covering no less than 95% of the daily git commands, so you can bookmark them if you need them.

1. Initialization related

Initialize a repository

git init myrepo
Copy the code

Clone a repository to your local myrepo directory

Git clone git://github.com/linux/linux.git myrepo git remote add origin git://github.com/linux/linux.git # specified (associated) remote warehouse address, Applies to repositories created locallyCopy the code

Two, configuration related

Viewing configuration Information

Git config --list git config --list git configCopy the code

Configure the.git file

Git config-e git config-e --globalCopy the code

Configure global authentication information, remove –global for the current repository configuration

git config --global user.name "user_git" git config --global user.email [email protected] git config --global user.password  "mypasswd"Copy the code

3. Related to routine operations

Git data is transferred in the working area, temporary storage area, local warehouse and remote warehouse area. The following picture can be clearly presented

Check the current state of the git file flow at any time

git status
Copy the code

Adds a file to the staging area

Git add <file> git add.Copy the code

Deleting files from staging area (adding useless files)

Git restore --staged <file> git reset <fileCopy the code

Delete or move files, rename them, and automatically commit them to the staging area. Used to process files that have been committed to the repository

git rm|mv <file>
Copy the code

Commit the changes to the local repository

git commit -m "change to..." git commit -am "change to ..." # For direct submission of modified files, new files cannot be submittedCopy the code

Undo a commit (which generates a commit record on the branch)

git revert <commit>
Copy the code

View the submission record

Git log git log --graph # git blame <fileCopy the code

View file modifications or differences

Git diff HEAD -- <file> git diff HEAD -- <fileCopy the code

Repeated hop (Version Rollback)

Git reset <commitid> # Git reset HEAD~1 # Back to the previous version git rest HEAD~n # Back to the first n versions git reset HEAD~n # Back to the first n versionsCopy the code

Commit the changes to the remote repository

Git push -u orgin master branch git push -u orgin master branchCopy the code

Pull the latest version of the remote repository

Git pull = merge git pull = merge git pull Git add <conflict-file> < rebaseCopy the code

Iv. Branch management

Viewing a Local Branch

git branch 
Copy the code

Create a branch

git branch <branchName>
Copy the code

Delete the branch

Git branch -d <branchName> # -dCopy the code

Switch branch

<branchName> <branchName> <branchName> Create branch and switchCopy the code

Pull the remote branch

Git checkout -b dev origin/developCopy the code

Checkout rolls back to a commit ID

Git checkout <commitid> does not affect the current workspace or branch (read only).Copy the code

Checkout rolls back a file to commitid

Git checkout <commit> <fileCopy the code

Branch operation — Merge branches

Fast mode, moving the head pointer (fast-forward), merges dev into the current branch

Git merge dev #Copy the code

Normal mode (no FF), equivalent to moving the head pointer to the new node, leaving the merge history branch.

git merge --no-ff -m "merge it" dev
Copy the code

Vi. Label management

Viewing the Tag List

git tag
Copy the code

Viewing Label Information

Git show v0.01 git show commit_id #Copy the code

marking

Git tag v0.01Copy the code

Mark a commit

Git tag -a v0.01-m "v0.01 release" f45212545 # git tag -m "v0.01 release" f45212545 #Copy the code

Remove the label

Git v0.01 tag - dCopy the code

By default, labels are only stored locally

Git push origin <tagname> git push originCopy the code

Deleting a Remote Label

Git tag -d v0.01 Git push origin :refs/tags/v0.01Copy the code

Seven, other

Work area temporary

git stash
Copy the code

View the staging workspace

git stash list
Copy the code

Restore the staging workspace without deleting the stash contents

Git stash apply git stash apply <stash@{n}> # Restore to the execution workspace git stash Drop # Delete stash contentsCopy the code

Stash contents are automatically deleted when the staging workspace is restored

git stash pop 
git stash pop <stash@{n}> 
Copy the code

Copy the commit to the current branch to reduce duplicate changes

git cherry-pick <commit>
Copy the code

Essential series articles:

Vim command: juejin.cn/post/696677…


Feel free to point out any shortcomings in this article in the comments section.

Welcome to collect, like and ask questions. Keep an eye on top water cooler managers and sometimes do more than just boil hot water.