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 basic operations of git under Linux and Windows

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

Share

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

This article mainly introduces "what are the basic operations of git under Linux and Windows". In the daily operation, I believe that many people have doubts about the basic operation of git under Linux and Windows. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what are the basic operations of git under Linux and Windows?" Next, please follow the editor to study!

1. Linux environment 1, install gitsudo apt-get install git2, set up git account information git config-global user.name "your git account user name" git config-global user.email "your mailbox" 3, set up credential helper to help us keep our code in memory for a certain period of time The second behavior sets the timeout time git config-- global credential.helper cachegit config-- global credential.helper 'cache-- timeout=3600'4, obtains the ssh key and remote GIT association ssh-keygen-t rsa-C "your mailbox" # and then returns all the way to cd ~ / .ssh cat id_rsa.pub# to copy the key in Terminal, adds it to the SSH public key of github's settings, and completes password-free login association # verifies ssh communication It is suggested that the other operations of ssh-T git@github.com# are almost the same as those of windows when the connection is successful. Push common command git init # initialize local warehouse git config-list # can view your git configuration information # submit the file to the local warehouse git add abc.cppgit commit-m "first commit" / /-m to specify the description of this submission # submit to repositorygit remote add origin "github warehouse ssh address" / / associated warehouse git push origin master # master is the branch name # if submitted to the same warehouse in the future After submitting it to the local warehouse, you can directly git push # clone project git clone "project ssh address" 6. When push reports an error, increase the cache git config http.postBuffer 52428800 / / (casually adjust according to file size) 2. Windows environment 1, version control Backup and modification 1) Local version control system

  stores the version number in the database to distinguish between recorded version changes.

2) centralized version control system (CVCS)

  has a server dedicated to storing revised versions of the version, and can easily locate related records with the help of version records.

3) distributed version control system (DVCS)

The   client not only extracts the latest version of the file snapshot, but mirrors the original code repository locally, and any server failure that cooperates with each other can be recovered afterwards with any mirrored local repository.

2. Installation and configuration of git under Windows 1) installation

  downloads and installs the corresponding version on the git official website, finds Git- > Git Bash in the menu, and the command line window appears, which means the installation is successful.

View the version:

Git-- version2) configure user name and mailbox git config-- gobal user.name "your user name" # configure username git config-- gobal user.email "your email" # configure mailbox git config-- list # View all configuration 3, three states of git files and working mode 1) three statuses

Submitted (committed): the data has been securely saved to the local database

Modified (modified): the file has been modified but has not been saved to the database

Staged: marks the current version of a modified file to be included in the next submitted snapshot

2) three work areas

Workspace: local project directory

Temporary storage area: take a snapshot of the modified file and add it to the temporary storage area

Git repository: the hidden directory of the workspace. Git, which is not a workspace, is the version library of git.

3) the workflow of git

Modify some files in the workspace

Snapshot the modified file and add it to the temporary storage area

Submit updates and permanently store snapshots stored in the staging area in the git repository

Pull: git Repository-> Local Workspace

Submit: local workspace-> staging area-> git repository

4. Create the version library and submit the file 1) initialize the local repository

  initializes an empty repository without any files locally.

Git init2) create a new folder git01.txt and add it to the staging area git add # add files to the staging area git add. # submit all files in the current directory git status # check the status of files git commit # submit the files from the temporary storage area to the local warehouse git log # view the complete submission log information git diff HEAD-- file # View the difference between previous submissions of the file method file

For example:

In Git Bash

Git init # create an empty repository git add git01.txt # add the file git01.txt to the cache git commit-m 'submit for the first time' # submit the file to the local warehouse, the contents in single quotes are the comments for this submission, you must have git status # to view the file status of the staging area git log # to view the complete submission record 5, file modification and submission modification

  can be modified directly in the workspace file, then added to the temporary storage area and submitted to the local warehouse

Note: must be added to the staging area before submission

1) submission and revocation of temporary storage documents

Submit: git add/git commit

Undo:

  is removed from the staging area:

Git restore-- staged git02.txt # remove the file from the staging area git02.txtgit reset HEAD git02.txt # cancel the last operation on the file git02.txt 2) version fallback

Simplify the display of submission records:

Git log-pretty=oneline

By default, the HEAD pointer points to the record that was last submitted. Version fallback is the version to which the HEAD pointer wants to fall back.

Git reset-- hard head ^ # rollback one version git reset-- hard head ^ # rollback two versions git reset-- hard HEAD~n # rollback n versions git reset-- hard "version identification number" # back or advance to the version where the version identification number is located git reflog # displays all submission records (including versions after the version HEAD points to) That is, you can display the record of every operation of the user. 3) File deletion git ls-files # View the file directory of the local warehouse git rm filename# delete files filename# another method: delete files in the workspace now Then submit the operation 6, remote warehouse 1) githubgit clone "project address" (github address) # download github project (may not log in) 2) ssh download (need to log in) # first need to generate a keyssh-keygen-t rsa-C "github mailbox" in gitbash # find the generated public key, open it and copy it Then add `SSH and GPG keys` # to github to verify whether you have successfully added ssh-T git@github.com# and you can be successfully authenticated (that is, ssh has been bound to github) # download project git clone "project address" (ssh address) 3) Local project (local warehouse) is pushed to remote warehouse # New warehouse in github # submit local project to local warehouse # Bind the local warehouse to the remote warehouse above github git remote add origin "github warehouse address" # push it to the trunk of the remote warehouse (the remote warehouse contains all submission records of the local warehouse) push updates after git push-u origin master# Just after the local submission is completed, directly command git push7 and git branch operation as follows

The   backbone is a project that is already online, and any operation in the branch will not affect the functionality of the trunk. After the branch is perfect, you can merge it into the trunk.

1) Local branch operation

Common basic commands

The command describes git checkout branch to switch to the specified branch git checkout-b new_branch create a new branch and switch to the new branch git branch-dbranch delete the specified branch git branch to view all branches, and * mark the current branch git merge branch merge branch git branch-m /-M oldbranch newbranch rename the branch, if the new_branch name branch already exists, you need to use-M to force renaming

Switch to the specified branch: git checkout branch

Create a new branch and switch to the new branch: git checkout-b new_branch

Delete the specified branch: git branch-d branch

View all branches and * mark the current branch: git branch

Merge branches: git merge branch

Rename the branch. If the new_branch name branch already exists, you need to use-M to force the rename: git branch-m |-M oldbranch newbranch

Note:

Branches can only be merged on trunk branches, not vice versa. (although git will not report an error, but this is not possible.)

The content of the branch is what the trunk has when the branch is created.

2) remote branch operation

Branch push and pull

Related command

Command description git branch-a View local and remote branches git push origin branch_name push local branch to remote git push origin: remote_branch delete remote branch (local branch is still reserved) git checkout-b local_branch origin/remote_branch pull remote specified branch and create branch locally

Get the latest status of the remote branch

Git fetch

The way the chart displays the operation record

Git log-- graph-- pretty=oneline3) Local branch conflict resolution # when the same line of the same file of the branch and the trunk is different, the merged branch will conflict # modify it according to the specific needs and make it the same. 4) multiple people cooperate with the operation conflict # two users have performed different operations on the same line of the same file # solution: pull the remote warehouse during the push period Push after the conflict is resolved locally according to the specific needs. 9. Label management

Label operation basic command git tag

Command description git tag tag_name New label Add tags by default for HEADgit tag-a tag_name-m 'xxx' and specify tag description information git tag view all tags git tag-d tag_name delete a local tag git push origin tag_name push local tags to remote git push origin-- tags push all unpushed local tags to remote git push origin: refs/tags/tag_name delete a remote tag 10, git basic operations under Idea 1) environment integration configuration

Configure- > Settings- > search git- > add the installation path of git in Path to Git executable (until git.exe)-> test- > version number indicates success-> add github

Or

File- > Other Settings- > Setting for New Projects- > Git/Git Hub

2) push the project to the remote warehouse

Project submitted to local warehouse-> create remote warehouse-> bind remote warehouse-> push to remote warehouse

At this point, the study on "what are the basic operations of git under Linux and Windows" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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