Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the six commands commonly used in git?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what are the six commands commonly used in git. It is very detailed and has a certain reference value. Friends who are interested must finish it!

The six commands commonly used in git are: 1, push command; 2, pull command; 3, commit command; 4, add command; 5, checkout command; 6, fetch/clone command.

Git has a lot of commands, and it's hard to remember them completely. Generally speaking, we just need to remember the six commands in the following figure.

The list of Git commands and the translation of individual special nouns are 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 and 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 settings 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 # Edit 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 specified files 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. # before adding each change, you will be asked to confirm # for multiple changes in the same file, you can submit $git add-p # to delete the workspace file and put the deletion in the temporary storage area $git rm [file1] [file2]. # stop tracking the specified file, but the file will remain in the workspace $git rm-cached [file] # renamed file And put the rename into 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 designated 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 # display all diff information when submitting $git commit-v # use a new commit Replace the previous commit # if there are no new changes in the code, 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 [file1] [file2].

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] # create a new branch Point to the specified commit$ git branch [branch] [commit] # create a 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] # switch to the previous branch $git checkout-# 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 into the current branch $git merge [branch] # Select a commit and merge into the current branch $git cherry-pick [commit] # Delete branch $git branch- d [branch-name] # Delete remote branch $git push origin-delete [branch-name] $git branch- dr [remote/branch]

VI. Label

# list all tag$ git tag # New tag in the current commit$ git tag [tag] # New tag in the specified commit$ git tag [tag] [commit] # Delete local tag$ git tag-d [tag] # Delete remote tag$ git push origin: refs/tags/ [tagName] # View tag information $git show [tag] # submit specified tag$ git push [remote] [tag] # submit all tag$ git Push [remote]-- tags # create a new branch Point to a tag$ git checkout-b [branch] [tag]

7. View information

# display the file with changes $git status # display the version history of the current branch $git log # display the commit history, and each time the commit changes $git log-- stat # search submission history, according to the keyword $git log-S [keyword] # shows all changes after a commit, each commit occupies a line $git log [tag] HEAD-- pretty=format:%s # shows all changes after a commit Its "submission description" must meet the search criteria $git log [tag] HEAD-- grep feature # displays the version history of a file, including file renaming $git log-- follow [file] $git whatchanged [file] # shows each diff$ git log-p [file] # related to the specified file # shows the last 5 submissions $git log-5-pretty-- oneline # shows all submitted users Sort by number of submissions $git shortlog-sn # shows who modified the specified file $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 [file] # shows the difference between the workspace and the latest commit of the current branch $git diff HEAD # shows the difference between the two commits $git Diff [first-branch]... [second-branch] # shows how many lines of code you wrote today $git diff-- shortstat "@ {0 day ago}" # shows the metadata and content changes of a submission $git show [commit] # shows a file that has changed a submission $git show-name-only [commit] # shows a submission Contents of a file $git show [commit]: [filename] # shows the most recent submission 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 # push 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 staging area and the workspace $git checkout [commit] [file] # restore all files of the staging area to the workspace $git checkout. # reset the specified file of the staging area, consistent with the previous commit, but the workspace remains the same $git reset [file] # resets the staging area and the workspace, and is consistent with the previous commit. $git reset-- hard # resets the pointer of the current branch to the specified commit and resets the staging area, but the workspace remains unchanged $git reset [commit] # resets the HEAD of the current branch to the specified commit, and resets the staging area and workspace Consistent with the specified commit $git reset-- hard [commit] # resets the current HEAD to the specified commit, but leaves 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] # temporarily remove uncommitted changes and move into $git stash$ git stash pop later

X. other

# generate a package for release $git archive is all the contents of this article "what are the six commands commonly used by git?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report