Resource List:

Git Book

Git tutorial

Git use detailed tutorial

The noun is introduced

-Jenny: Well, I’m working in a Workspace.

Index/Stage: temporary storage area

Repository: a warehouse or local Repository

Remote: Remote repository

Understanding these nouns will form a body of knowledge in your mind that will help you understand the following specific commands.

Git git

Create a SSH Key

$ ssh-keygen -t rsa -C "[email protected]"
Copy the code

warehouse

#Create a new Git code base in the current directory
$ git init

#Create a new directory and initialize it as a Git code base
$ git init [project-name]

#Download a project and its entire code history
$ git clone [url]
Copy the code

Add/delete files

#Adds the specified file to the staging area
$ git add [file1] [file2] ...

#Adds the specified directory to the staging area, including subdirectories
$ git add [dir]

#Adds all files from the current directory to the staging area
$ git add .

#Confirmation is required before each change is added
#Multiple changes to the same file can be committed in batches
$ git add -p

#Delete the workspace file and place the deletion in the staging area
$ git rm [file1] [file2] ...

#Stops tracking the specified file, but it remains in the workspace
$ git rm --cached [file]

#Rename the file and place the rename in the staging area
$ git mv [file-original] [file-renamed]
Copy the code

Submit code

#Submit temporary storage area to warehouse area
$ git commit -m [message]

#Submit documents designated for the staging area to the warehouse area
$ git commit [file1] [file2] ... -m [message]

#Commit the changes to the workspace since the last commit, directly to the warehouse
$ git commit -a

#Display all diff information when committing
$ git commit -v

#Use a new COMMIT instead of the previous commit
#If there are no new changes to the code, it is used to overwrite the commit information from the last COMMIT
$ git commit --amend -m [message]

#Redo the last COMMIT and include new changes to the specified file
$ git commit --amend [file1] [file2] ...
Copy the code

branch

#Lists all local branches
$ git branch

#List all remote branches
$ git branch -r

#Lists all local and remote branches
$ git branch -a

#Create a new branch, but remain in the current branch
$ git branch [branch-name]

#Create a new branch and switch to it
$ git checkout -b [branch]

#Create a new branch that points to the commit
$ git branch [branch] [commit]

#Create a new branch and establish a trace relationship with the specified remote branch
$ git branch --track [branch] [remote-branch]

#Switch to the specified branch and update the workspace
$ git checkout [branch-name]

#Switch to the previous branch
$ git checkout -

#Establish a trace relationship between an existing branch and a specified remote branch
$ git branch --set-upstream [branch] [remote-branch]

#Merges the specified branch into the current branch
$ git merge [branch]

#Select a COMMIT and merge it into the current branch
$ git cherry-pick [commit]

#Delete the branch
$ git branch -d [branch-name]

#Deleting a Remote Branch
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
Copy the code

The label

#List all tags
$ git tag

#Create a new tag for the current commit
$ git tag [tag]

#Create a new tag before specifying commit
$ git tag [tag] [commit]

#Deleting a Local Tag
$ git tag -d [tag]

#Deleting a Remote Tag
$ git push origin :refs/tags/[tagName]

#Viewing tag Information
$ git show [tag]

#Submit the specified tag
$ git push [remote] [tag]

#Submit all tags
$ git push [remote] --tags

#Create a new branch that points to a tag
$ git checkout -b [branch] [tag]
Copy the code

Check the information

#The changed file is displayed
$ git status

#Displays the version history of the current branch
$ git log

#Displays the commit history and the files that changed each commit
$ git log --stat

#Search submission history by keyword
$ git log -S [keyword]

#Displays all changes after a commit, with each commit occupying one row
$ git log [tag] HEAD --pretty=format:%s

#Displays all changes made after a COMMIT"Submit instructions"The search criteria must be met
$ git log [tag] HEAD --grep feature

#Displays the version history of a file, including file renaming
$ git log --follow [file]
$ git whatchanged [file]

#Displays each diff associated with the specified file
$ git log -p [file]

#Displays the last five commits
$ git log -5 --pretty --oneline

#Displays all submitted users, sorted by number of submissions
$ git shortlog -sn

#Show who modified the specified file and when
$ git blame [file]

#Shows the difference between staging area and workspace
$ git diff

#Shows the difference between the staging area and the last COMMIT
$ git diff --cached [file]

#Displays the difference between the workspace and the latest COMMIT for the current branch
$ git diff HEAD

#Displays the difference between two commits
$git diff [first-branch]... [second-branch]

#Shows how many lines of code you wrote today
$ git diff --shortstat "@{0 day ago}"

#Displays metadata and content changes for a commit
$ git show [commit]

#Displays the files that have changed during a commit
$ git show --name-only [commit]

#Displays the contents of a file at the time of a commit
$ git show [commit]:[filename]

#Displays the most recent commits for the current branch
$ git reflog
Copy the code

Remote synchronization

#Download all changes to the remote repository
$ git fetch [remote]

#Display all remote warehouses
$ git remote -v

#Displays information about a remote repository
$ git remote show [remote]

#Add a new remote repository and name it
$ git remote add [shortname] [url]

#Retrieve the changes from the remote repository and merge them with the local branch
$ git pull [remote] [branch]

#Upload the local specified branch to the remote repository
$ git push [remote] [branch]

#Push current branch to remote repository forcibly, even if there are conflicts
$ git push [remote] --force

#Push all branches to the remote repository
$ git push [remote] --all
Copy the code

undo

#Restores the specified file from the staging area to the workspace
$ git checkout [file]

#Restores the specified files of a COMMIT to the staging and workspace
$ git checkout [commit] [file]

#Restores all files from the staging area to the workspace
$ git checkout .

#Resets the specified file in the staging area, same as the last commit, but with the same workspace
$ git reset [file]

#Reset the staging area and workspace as the last COMMIT
$ git reset --hard

#Reset the pointer to the current branch to specify COMMIT, and reset the staging area, but the workspace remains the same
$ git reset [commit]

#Reset the HEAD of the current branch to specify a COMMIT, and reset the staging area and workspace to match the specified COMMIT
$ git reset --hard [commit]

#Reset the current HEAD to specify commit, but leave the staging area and workspace unchanged
$ git reset --keep [commit]

#Create a commit to undo the specified COMMIT
#Any changes to the latter are cancelled out by the former and applied to the current branch
$ git revert [commit]

#Uncommitted changes are temporarily removed and moved in later
$ git stash
$ git stash pop
Copy the code

The commonly used skill

The help command

$ git --help
Copy the code

The status command

Git status will prompt you to display the current file status and give you some suggestions, so you don’t get confused.

$ git status
Copy the code

For more information, you can follow my personal blog: Yizhu Station

Also welcome to follow my official account: Yizhuxiaozhan, QR code: