This article is mainly used to document some of the common scenarios in Git-managed projects and their corresponding commands, to make it easy for you and others to quickly query. If there is any mistake, please correct me.
View the help documentation for a git command
git help [command]
View the status of individual files
git status
Clone a warehouse
git clone [url]
Initialize a warehouse
git init
Put the file in staging area
git add [file-name]
Submit
git commit
Stop trace files and delete files
git rm [file-name]
Stop tracking and delete files that have been modified and added to staging area
git rm -f [file-name]
Stop tracking but not delete files
git rm --cached [file-name]
Move or modify file names
git mv [old-name] [new-name]
Show changes to files that have been placed in staging area
git diff --cached
Display changes to files that are not placed in staging area
git diff [path/to/file]
Show all local branches of the current warehouse
git branch
Show all remote branches of the current warehouse
git branch -r
Show all branches of the current warehouse (both local and remote)
git branch -a
Create a local branch
git branch [branch-name]
Switch to a local branch
git checkout [branch-name]
Merge a branch into the current branch
git merge [branch-name]
Delete a branch that has been merged
git branch -d [branch-name]
Delete a branch that has not yet been merged
git branch -D [branch-name]
The merge code has not yet been submitted and you want to undo the merge
git reset --hard HEAD
View all Submissions
git log
View all submissions and corresponding code diff for each submission
git log -p
View all submissions, as well as the files involved in each submission, and how many rows the files were deleted/added
git log --stat
View the difference between the current working directory and a branch
git diff [branch-name]
View the difference between a directory and a branch in the current working directory
git diff [branch-name] -- [path]
Modify the last Commit
git commit --amend
Revoke a file that has been staged
git reset HEAD [file-name]
Undo changes to a file
git checkout -- [file-name]
View the currently configured remote warehouse
git remote
View the currently configured remote warehouse and the corresponding address
git remote -v
Add a remote repository
git remote add [remote-name] [url]
Capture data from a remote repository
git fetch [remote-name] [branch-name]
Push data to a remote repository
git push [remote-name] [branch-name]
View a remote warehouse information
git remote show [remote-name]
Renaming a remote repository
git remote rename [old-name] [new-name]
Delete a remote warehouse
git remote rm [remote-name]
Show existing labels
git tag
Search for a specific tag
git tag -l [keyword]
Create Lightweight labels
git tag [tag-name]
Create a label with notes
git tag -a [tag-name] -m [msg]
Tag a previous commit
git tag -a [tag-name] [hash]
View information for a tag
git show [tag-name]
Push tags to the remote repository
git push [remote-name] [tag-name]
Push all local labels to the remote repository at once
git push [remote-name] --tags
To rebase branch B into branch a
git checkout b git rebase a
Before switching to another branch, you do not want to submit the changes on the current branch, you can use the storage function
git stash
Show All Storage
git stash list
Apply your storage
git stash apply [stash-name]
Git Common Command table