What are the commonly used git commands in Linux systems
Editor to share with you what the git commands commonly used in the Linux system are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Git is an open source distributed version control system for efficient and high-speed version management of projects ranging from very small to very large.
The following is a list of commonly used Git commands that I have compiled. Several special nouns are translated as follows:
Workspace: workspace Index / Stage: temporary storage area Repository: warehouse area (or local warehouse) Remote: remote warehouse
I. create a new code base
# create a new Git code base in the current directory $git init# create a new directory, initialize it to the Git code base $git init [project-name] # download a project and its entire code history $git clone [url]
II. Configuration
The configuration file for Git is .gitconfig, which can be in the user's home directory (global configuration) or in the project directory (project configuration).
# display current Git configuration $git config-- list# edits Git configuration file $git config-e [--global] # set user information when submitting code $git config [--global] user.name "[name]" $git config [--global] user.email "[email address]"
III. Add / delete files
# add the specified file to the staging area $git add [file1] [file2] # add the specified directory to the staging area, including the subdirectory $git add [dir] # add all files in the current directory to the staging area $git add. # Delete the workspace file and put this deletion in the staging area $git rm [file1] [file2]. # stop tracking the specified file However, the file will remain in the workspace $git rm-cached [file] # renamed file, and the renamed file will be placed in the staging area $git mv [file-original] [file-renamed]
IV. Code submission
# submit the staging area to the warehouse area $git commit-m [message] # submit the specified files of the staging area to the warehouse area $git commit [file1] [file2]-m [message] # submit the changes to the workspace since the last commit, directly to the warehouse area $git commit-a # to display all diff information when submitting $git commit-v# use a new commit instead of the previous submission # if there are no new changes in the code Then it is used to rewrite the submission information of the last commit $git commit-- amend-m [message] # redo the last commit and include the new change of the specified file $git commit-amend
V. 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 at the current branch $git branch [branch-name] # New branch, and switch to that branch $git checkout-b [branch] # New branch, point to the specified commit$ git branch [branch] [commit] # New branch 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] # to establish a tracking relationship between the existing branch and the specified remote branch $git branch--set-upstream [branch] [remote-branch] # merge the specified branch to the current branch $git merge [branch] # Select a commit Merge into current branch $git cherry-pick [commit] # Delete branch $git branch- d [branch-name] # Delete remote branch $git push origin-- delete $git branch- dr
VI. Label
# list all tag$ git tag# create a new tag in the current commit$ git tag [tag] # create a new tag in the specified commit$ git tag [tag] [commit] # View tag information $git show [tag] # submit specified tag$ git push [remote] [tag] # submit all tag$ git push [remote]-- tags# create a new branch and point to a tag$ git checkout-b [branch] [tag]
7. View information
# display the file with changes $git status# displays the version history of the current branch $git log# displays the commit history, and the file $git log-- stat# shows the version history of a file each time commit changes Includes file renaming $git log-- follow [file] $git whatchanged [file] # shows each diff$ git log-p [file] # shows who modified the specified file and when $git blame [file] # shows the difference between the staging area and the workspace $git diff# shows the difference between the staging area and the last commit $git diff-- cached [] # shows the workspace and the current section The difference between the latest commit $git diff HEAD# shows the difference between the two submissions $git diff [first-branch]... [second-branch] # shows the metadata and content changes of one submission $git show [commit] # shows the files that have changed in one submission $git show-- name-only [commit] # shows the most recent submissions of the current branch $git reflog
8. Remote synchronization
# download all changes to the remote warehouse $git fetch [remote] # display all remote warehouses $git remote-v # display information about a remote warehouse $git remote show [remote] # add a new remote warehouse and name it $git remote add [shortname] [url] # retrieve the changes to the remote warehouse And merge $git pull [remote] [branch] # upload the local specified branch to the remote warehouse $git push [remote] [branch] # forcibly push the current branch to the remote warehouse, even if there is a conflict $git push [remote]-- force# pushes all branches to the remote warehouse $git push [remote]-- all
IX. Revocation
# restore the specified files of the staging area to the workspace $git checkout [file] # restore the specified files of a commit to the workspace $git checkout [commit] [file] # restore all files of the previous commit to the workspace $git checkout. # reset the specified files of the staging area, consistent with the previous commit, but the workspace remains the same $git reset [file] # reset the staging area and the workspace Consistent with the last commit $git reset-- hard# resets the pointer of the current branch to the specified commit and resets the staging area, but the workspace does not change $git reset [commit] # resets the HEAD of the current branch to the specified commit, and resets the staging area and the workspace, consistent with the specified commit. $git reset-- hard [commit] # resets the current HEAD to the specified commit But leave the staging area and workspace unchanged $git reset-keep [commit] # create a new commit, all changes used to undo the specified commit# will be offset by the former, and applied to the current branch $git revert [commit] above is "what are the git commands commonly used in the Linux system?" all the content of this article, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!