Git learning: Git commands

Insert picture description here
Workspace: Work area
Index / Stage: Temporary storage area
Repository: Warehouse area (or local warehouse)
Remote: Remote warehouse
1. Initialization

Create a new Git code repository in the current directory
git init
initialize a new directory
git init [project-name]
download the remote warehouse project to the local
git clone [url]
2. Configuration

The configuration file is divided into all configuration and warehouse configuration. The global configuration file is ~/.gitconfig, and the current project configuration file is .git/config.
We usually modify the remote and user. The remote configuration is the remote warehouse address, and the user configuration is the username and password you submitted. The user name and password used during the push will also be seen in the log.
[user]
name = user name
email = user [email protected]
[remote “origin”]
url = https://github.com/july/july.git
The configuration of the warehouse can be configured with the following commands, if it is global , Just add --global.
git config user.name username
3. Add/Delete

Add the specified file to the temporary storage area
git add [file1] [file2] …
Add the specified directory to the temporary storage area, including the subdirectory
`git add [dir]''
Add all files in the current directory to the temporary storage area
git add.
Line by line Check and submit, y is ok, n is to cancel
git add -p to
delete the workspace file, and put the deletion into the temporary storage area
git rm [file1] [file2]…
4. Code submission

Submit the temporary storage area to the warehouse area, and fill in the remarks
git commit -m [message]
Submit the specified files in the temporary storage area to the warehouse area
git commit [file1] [file2]… -m [message]
Modify the last submission, you need Modify the submission before push
git commit --amend
append new content to the last submission without push git commit --amend --no-edit
5. Branch

List all local branches
git branch
List all remote branches
git branch -r
List all local branches and remote branches
git branch -a
Create a new branch, but still stay in the current branch
git branch [branch-name]
Create a new branch, and Switch to the branch
git checkout -b [branch]
Create a new branch and establish a tracking 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. This operation is very common and useful.
git checkout-
establish a tracking relationship,
git branch --set-upstream [branch] [remote-branch]
merge between the existing branch and the specified remote branch Specify the branch to the current branch
git merge [branch] merge
from other branches commit
git cherry-pick [commit]
delete the local branch
git branch -d [branch-name]
delete the remote branch
git push origin --delete [branch-name]
6. Remote synchronization

Download all changes of remote repositories
git fetch [remote]
Display the configuration of all remote repositories
git remote -v
Add a new remote repository and name it
git remote add [shortname] [url]
Update the changes of remote branches
git pull [remote] [branch]
Push local designated branch to remote warehouse
git push [remote] [branch]
7. Cancel

Restore the specified files in the temporary storage area to the workspace
git checkout [file]
Restore all the files in the temporary storage area to the workspace
git checkout.
Reset the specified files in the temporary storage area to be consistent with the previous commit, but the workspace remains unchanged
git reset [file]
Reset the temporary storage area and the work area, consistent with the last commit
git reset --hard
reset the pointer of the current branch to the specified commit, and reset the temporary storage area, but the work area remains unchanged
git reset [commit ]
Reset the HEAD of the current branch to the specified commit, and reset the temporary storage area and the work area at the same time, consistent with the specified commit
git reset --hard [commit]
Create a new commit to cancel the specified commit
git revert [commit]
temporarily The submitted changes are temporarily stored, and then taken out
git stash
git stash pop
8. Information query

Display changed files
git status
display historical information
git log
search for submission history, according to the keyword
git log -S [keyword]
display the version history of a file
git log --follow [file]
display who and when the specified file is Modified
git blame [file] to
display the difference between the temporary storage area and the work area
git diff to
display the metadata and content changes of a
commit git show [commit] to
display the content of a file during a
commit git show [commit]: [filename]

Guess you like

Origin blog.csdn.net/weixin_41812784/article/details/108098689