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

Introduction to common commands of git

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article is to share with you an introduction to common git commands. The editor thought it was very practical, so I shared it with you to learn. The following information is about the common commands of git.

1) basic environment 1) Local initialization: generate .git directory, do not easily modify the command: git init 2) set signature: distinguish the identity of different developers, the signature set here has nothing to do with the account and password of logging in to the remote library (code center) * Project level / warehouse level: valid only in the current local library scope Command: gitconfig user.name admingit config user.email admin@admin.com information saved location: .git / config file * system user level: login to the current operating system user scope command: gitconfig-- global user.name admingit config-- global user.email admin@admin.com information saved location: ~ / .gitconfig file * level Other priorities: (1) proximity principle: the project level takes precedence over the system user level Use project-level signatures when both exist (2) if there is only a user-level signature of the system, the user-level signature of the system shall prevail; (3) if both of them do not exist, errors will be reported frequently in future operations; 2) the basic operation git status # check the status of the workspace and the staging area git add 123.txt # submit the workspace files to the staging area (either for a single file or using "." Indicates all files in the current directory) git rm-- cached 123.txt # recalls the files in the staging area and replaces them in the workspace git commit-m "first commit 123.txt" # submits the contents of the staging area to the local library (- m description information) 3) several ways to view history git log # View previously submitted log information git log-- pretty=oneline # View previously submitted log information (displayed on one line) git log-- oneline # View previously submitted log information (displayed in a more concise way) git Reflog # shows all historical HEAD pointers 4) controls the version forward and backward

1) Operation based on index value (recommended)

Git reset-- hard d67b2ca #-- hard is followed by the index value queried by the git reflog command

2) use the ^ symbol (only backward)

Git reset-- hard head ^ # back one version (^ one means back one version)

3) use the ~ symbol (only backward)

Git reset-- hard HEAD~n # n means a few steps back. 5) Delete the file and retrieve it.

Premise: before deletion, the status of the file when it exists is submitted to the local library

Action:

Git reset-- hard [pointer position]

1) the deletion operation has been submitted to the local library: the pointer position points to the history

2) the deletion operation has not been submitted to the local library: the pointer position uses HEAD

6) compare file differences git diff [filename] # compare files in the workspace with the cache git diff [historical versions in the local library] [filenames] # compare the files in the workspace with the local library history git diff [historical versions in the local library] # compare all files in the workspace with the local library 7) git branch management

Git branch [Branch name] # create a branch

Git branch-v # View all branches The "*" sign indicates the current branch (the-v option is not added) git checkout [branch name] # switch branch git checkout-b [branch name] # create branch and switch branch git merge [merged branch name] # Quick merge branch (provided that it cannot be on the merged branch) git branch-d [branch name] # Delete specified branch git branch-D [branch name] # force delete specified branch git stash # restore the status of the current version library temporary storage git stash pop # and delete temporarily stored information git stash apply # restore temporarily stored information But do not delete information git stash drop # delete temporary storage information git stash show # view temporary storage information git remote add origin https://github.com/lvzhenjiang-hub/test.git # give the address of the remote warehouse an individual name The name is origingit remote # to see if the current version library belongs to the remote version library git remote-v # View details git push origin master # push the local master branch to the remote repository git checkout-b dev origin/dev # create a local dev branch and associate it to the dev branch git fetch origin master of the remote repository # download from remote warehouse to local git merge origin/master # merge remote branches to git pull origiin master # download master branch of remote warehouse to local And merge, mainly used to resolve conflicts git branch-- set-upstream-to=origin/dev dev associates the local dev branch to the dev branch of the remote repository git branch-r-d origin/dev deletes the specified remote dev branch git push origin: dev submits the deleted remote branch to the remote version repository

This is the end of the common commands about git. I hope the above content can be helpful to you and learn more knowledge. If you like this article, you might as well share it for more people to see.

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

Servers

Wechat

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

12
Report