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 common commands in Git and how to use them?

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the common commands of Git and how to use them". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "what are the common commands of Git and how to use them?"

Detailed explanation of git commands and common commands

Git is a commonly used version control tool. Knowing more about commands will save a lot of time. The following picture is a better one. Post it and have a look.

About git, you need to know a few nouns first, 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 $git init// in the current 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 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 the current git configuration $git config-- list// edits the git configuration file $git config-e [--global] / / sets the user information when submitting the 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 from the current directory to the staging area $git add. / / before adding each change, you will be required to confirm / / for multiple changes to the same file, you can submit $git add-pthumb / delete workspace files in stages. And put the deletion into the staging 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 the renamed file will be placed in the staging area $git mv [file-original] [file-renamed]

IV. Code submission

/ / submit staging area to warehouse area $git commit-m [message] / / submit specified files of temporary storage area to warehouse area $git commit [file1] [file2].-m [message] / / submit changes to the workspace since the last commit, directly to the warehouse area $git commit-a git commit / display all diff information at the time of submission $git commit-vUnip / 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- branch-name / list all local and remote branches $git branch- branch-name / create a new branch, but still stay at the current branch $local [branch-name] / / create a 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 to the current branch $git merge [branch] / / Select a commit, merge into the current branch $git cherry-pick [commit] / / delete the branch $git branch- d [branch-name] / / delete the 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// creates a new branch 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// search submission history for each commit change, and displays all changes after a commit according to the keyword $git log-s [keyword] / / Each commit occupies a line of $git log [tag] head-- pretty=format:%s// shows all changes after a commit, and its "submission description" must meet the search criteria $git log [tag] head-- grep feature// displays the version history of a file. Include file renaming $git log-- follow [file] $git whatchanged [file] / / display each diff$ git log-p [file] / / display 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 previous 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 Different $git diff [first-branch]... [second-branch] / shows how many lines of code you wrote today $git diff-- shortstat "@ {0 day ago}" / / shows metadata and content changes in a submission $git show [commit] / / shows a file that has changed in a submission $git show-- name-only [commit] / / shows a submission Contents of a file $git show [commit]: [filename] / / displays 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 staging area and the workspace $git checkout [commit] [file] / / restore all files of the staging area to the workspace $git checkout. / / reset the specified files of the staging area, consistent with the previous commit, but the workspace remains unchanged $git reset [file] / / resets the staging area and the workspace Consistent with previous 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 the $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 to the latter used to undo the specified commit// will be offset by the former, and apply to the current branch $git revert [commit] / / remove uncommitted changes temporarily, and then move in $git stash$ git stash pop later

X. other

/ / generate a compressed package $git archive that can be released. I believe you have a better understanding of what common Git commands are and how to use them. You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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