noun

  • Master: The default development branch
  • Origin: default remote version library
  • Index/Stage: temporary storage area
  • -Jenny: Well, I’m working in a Workspace.
  • A Repository is a Repository.
  • Remote: Remote repository

New code base

Create a new Git code base in the current directory

 git init
Copy the code

Create a new directory and initialize it as a Git code base

git init [project-name]
Copy the code

Download a project and its entire code history

git clone [url]
Copy the code

configuration

Git’s Settings file is.gitconfig, which can be in the user home directory (global configuration) or in the project directory (project configuration).

Displays the current Git configuration

git config --list
Copy the code

Edit the Git configuration file

git config -e [--global]
Copy the code

Sets the user information when submitting code

git config [--global] user.name "[name]"
git config [--global] user.email "[email address]"
Copy the code

Add/delete/modify files

Check the status

git status
Copy the code

Viewing changes

git diff
Copy the code

Adds the specified file to the staging area

git add [file1] [file2] ... Git add [dir] git add [dir]Copy the code

Adds all files from the current directory to the staging area

git add .
Copy the code

Before adding each change, you are asked to confirm that multiple changes to the same file can be committed in batches

git add -p
Copy the code

Delete the workspace file and place the deletion in the staging area

git rm [file1] [file2] ...
Copy the code

Stops tracking the specified file, but it remains in the workspace

git rm --cached [file]
Copy the code

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]
Copy the code

Submit documents designated for the staging area to the warehouse area

git commit [file1] [file2] ... -m [message]
Copy the code

Commit the changes to the workspace since the last commit, directly to the warehouse

git commit -a
Copy the code

Display all diff information when committing

git commit -v
Copy the code

A new COMMIT is used to override the commit information from the previous commit if there are no new changes in the code

git commit --amend -m [message]
Copy the code

Redo the last COMMIT and include new changes to the specified file

git commit --amend [file1] [file2] ...
Copy the code

branch

Displays all local branches

git branch
Copy the code

List all remote branches

git branch -r
Copy the code

Lists all local and remote branches

git branch -a
Copy the code

Create a new branch, but remain in the current branch

git branch [branch-name]
Copy the code

Create a new branch and establish a trace relationship with the specified remote branch

git branch --track [branch] [remote-branch]
Copy the code

Delete the branch

git branch -d [branch-name]
Copy the code

Deleting a Remote Branch

git push origin --delete [branch-name]
git branch -dr [remote/branch]
Copy the code

Create a new branch and switch to it

git checkout -b [branch]
Copy the code

Switch to the specified branch and update the workspace

git checkout [branch-name]
Copy the code

Switch to the previous branch

git checkout -
Copy the code

Establish a trace relationship between an existing branch and a specified remote branch

git branch --set-upstream [branch] [remote-branch]
Copy the code

Merges the specified branch into the current branch

git merge [branch]
Copy the code

Derivatives specify a branch to the current branch

git rebase <branch>
Copy the code

Select a COMMIT and merge it into the current branch

git cherry-pick [commit]
Copy the code

The label

Git tag -d <tagname> git tag -d <tagnameCopy the code

Deleting a Remote Tag

git push origin :refs/tags/[tagName]
Copy the code

Viewing tag Information

git show [tag]
Copy the code

Submit the specified tag

git push [remote] [tag]
Copy the code

Submit all tags

git push [remote] --tags
Copy the code

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
Copy the code

Displays the version history of the current branch

git log
Copy the code

Displays the commit history and the files that changed each commit

git log --stat
Copy the code

Search submission history by keyword

git log -S [keyword]
Copy the code

Displays all changes after a commit, with each commit occupying one row

git log [tag] HEAD --pretty=format:%s
Copy the code

Displays all changes made after a COMMIT whose “commit instructions” must match the search criteria

git log [tag] HEAD --grep feature
Copy the code

Displays the version history of a file, including file renaming

git log --follow [file]
git whatchanged [file]
Copy the code

Displays each diff associated with the specified file

git log -p [file]
Copy the code

Displays the last five commits

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

Displays all submitted users, sorted by number of submissions

git shortlog -sn
Copy the code

Show who modified the specified file and when

git blame [file]
Copy the code

Shows the difference between staging area and workspace

git diff
Copy the code

Shows the difference between the staging area and the last COMMIT

git diff --cached [file]
Copy the code

Displays the difference between the workspace and the latest COMMIT for the current branch

git diff HEAD
Copy the code

Displays the difference between two commits

git diff [first-branch]... [second-branch]Copy the code

Shows how many lines of code you wrote today

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

Displays metadata and content changes for a commit

git show [commit]
Copy the code

Displays the files that have changed during a commit

git show --name-only [commit]
Copy the code

Displays the contents of a file at the time of a commit

git show [commit]:[filename]
Copy the code

Displays the most recent commits for the current branch

$ git reflog
Copy the code

Remote operation

Download all changes to the remote repository

git fetch [remote]
Copy the code

Retrieve the changes from the remote repository and merge them with the local branch

git pull [remote] [branch]
Copy the code

Display all remote warehouses

git remote -v
Copy the code

Displays information about a remote repository

git remote show [remote]
Copy the code

Add a new remote repository and name it

git remote add [shortname] [url]
Copy the code

Upload the local specified branch to the remote repository

git push [remote] [branch]
Copy the code

Push current branch to remote repository forcibly, even if there are conflicts

git push [remote] --force
Copy the code

Push all branches to the remote repository

git push [remote] --all
Copy the code
Git push <remote> :<branch/tag-nameCopy the code

undo

Git checkout HEAD <file> # Restate the current status of the uncommitted git file Log --before="1 days" # return to the previous version of 1 dayCopy the code

Restores the specified file from the staging area to the workspace

git checkout [file]
Copy the code

Restores the specified files of a COMMIT to the staging and workspace

git checkout [commit] [file]
Copy the code

Restores all files from the staging area to the workspace

git checkout .
Copy the code

Resets the specified file in the staging area, same as the last commit, but with the same workspace

git reset [file]
Copy the code

Reset the staging area and workspace as the last COMMIT

git reset --hard
Copy the code

Reset the pointer to the current branch to specify COMMIT, and reset the staging area, but the workspace remains the same

git reset [commit]
Copy the code

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]
Copy the code

Reset the current HEAD to specify commit, but leave the staging area and workspace unchanged

git reset --keep [commit]
Copy the code

Create a COMMIT that cancels all changes to the specified COMMIT and applies them to the current branch

git revert [commit]
Copy the code

Uncommitted changes are temporarily removed and moved in later

git stash
git stash pop
Copy the code

other

Generate a zip package ready for publication

git archive
Copy the code