Git version management

Keywords: git

gitee usage process

First, download and install git software, then register gitee or github account, and then create a warehouse on the platform.

  • Configure the user name and mailbox in git command
git config --global user.name "Name "

git config –global user.email "Mailbox
  • Set SSH KEY

First generate the ssh key in the local git command, and then add the ssh public key in the personal settings on gitee or github. After receiving an email, it basically means OK

​
ssh-keygen –t rsa –C xxx@xxx.com(mailbox)

//If no error is reported, press enter three times according to the prompt. When you see the content of a rectangular box, it indicates that it has been generated

​
cat ~/.ssh/id_rsa.pub     //View ssh through this command
ssh –T git@gitee.com   take ssh fill git After entering on the platform  

hi "nickname" appears to indicate ok

  • Only one branch (master)
git init //Initialize a new local warehouse (in the project folder)

git add . //Add tracking file point is to add all files in the directory

git commit –m "v1.0"//Single quotation marks are linux and double quotation marks are windows to submit files to the warehouse

git remote add origin "git "Remote address"

git push –u origin master //Push all contents of the local repository to the master on the remote repository

git push –f origin master or git push origin master –force //Forced push is generally not recommended, and overwriting will occur

  • Upload a separate branch
git init

git add . //Add file

git commit –m "dev"

git branch dev //Create branch

git checkout dev //Switch branch

git commit –m "Name "

git remote add origin "git Warehouse address(To.git Suffix removal)"

git push origin dev//Upload branch

  • Merge branch
  1. First switch to the master branch
git checkout master

  1. If it is developed by multiple people, you need to pull down the code on the remote master
git pull origin master

  1. Then merge the branch code into the master
git merge dev
  1. View status and execute submit command
git status

       There is a commit that needs to be push ed to the remote master

  1. Final execution
git push origin master Push to master On main branch
  • Merge 2
  1. First, let's look at which branch is currently located
git branch
  1. Create a local branch (if there is no dev branch, it will be created and switched to dev2)
git checkout –b dev
  1. Make changes on the branch dev, and the changes are complete (the commit LD after commit needs to be saved)

    

git add.

git commit –m ""Submit information"
  1. Back to the master branch
git checkout master
  1. Update code
git pull origin master
  1. Merge the updates of dev (commit LD is when dev commits)
git cherry-pick commitId

When cherry pick, the automatic submission is not successful, which indicates that there is a conflict

  1. If there is a conflict, resolve it manually, and then add. You can call add and continue directly without committing (which is equal to committing again)
git add .

git cherry-pick –continue

  1. You can then view the currently submitted information
git log -3

  1. Finally, you can push

   

git push –u origin master

perhaps

  

git push origin HEAD:refs/for/master

7, git resolves remote and local conflicts

              When using git pull code

              Please, commit your changes or stage them before you can merge

       Reason: the updated content conflicts with the locally modified content. Submit the change first or save the locally modified content temporarily

      

use git stash

       use git stash list View cache clips

      

       git pull origin master


 Then merge the modified code into the updated code

       git stash pop stash@{0}

8, Create remote branch and commit

1.adopt git branch –r Command to view remote branches

2. Create a new branch from an existing branch

git checkout –b dev

No branch was created on the remote warehouse at this time

  1. Establish local to remote warehouse link
git push --set-upstream origin dev //dev is the name of the branch created

9, Both GitHub and Gitee are associated

1.git remote rm origin //Delete the associated remote library named origin

2.relation gitee Remote library

       git remote add gitee git@gitee.com....



3.relation github

       git remote add github git@github.com...

  git add add extra files  
Such mistakes are due to, sometimes may

git add . (Space+ Dot) indicates all files in the current directory. Other files will be submitted accidentally

git add If the wrong file is added

Undo operation

git status Have a look first add Files in 
git reset HEAD If you don't follow anything, it's the last time add Everything in it has been cancelled 
git reset HEAD XXX/XXX/XXX.java Is to undo a file

Posted by pas07920 on Tue, 26 Oct 2021 19:03:43 -0700