Basic operation

Configure global name and email

git config --global user.name "name" 
git config --global user.email "email" 
Copy the code

Generate the SSH Key

ssh-keygen -t rsa -C "youremail"  
Copy the code
  • There will be an id_rsa.pub file in your C:\Users\ administrator. SSH directory. Open it with notepad and copy the values inside

Cloning project

git cloneThe project addressCopy the code

Pull the project

git pull 
Copy the code

Upload the project

Git push origin git push origin git push origin git push originCopy the code

Branch operation

The new branch

Git branch Specifies the branch nameCopy the code

Switch branch

Git Checkout branch nameCopy the code

Merging branches

When you pull the main branch online to local but you don’t want to make changes directly on it, you create a new local branch to make changes, and when you are done you need to cut back to the main branch and merge the sub-branches

Git Merge Local sub-branchCopy the code

Deleting a specified branch

Git branch -d Specifies the branch nameCopy the code

Commit Merge operation

When your local commit wants to merge multiple entries into one, do the following

  1. The first to use
git log--oneline // Display local commit --oneline display can be added or not on a lineCopy the code
  1. Find the last commit_id(hash) that you want to finally merge
git rebase -i commit_id(hashValue) // all merged into commit_idCopy the code

You should select the commit_id value below add1

3. Notice that there is a pick on the Vim screen

  • Pick means that the commit will be performed

  • A squash means that this commit is merged with the previous commit

    • Vi Common commands:
      • Esc: Switches to the COMMAND line mode
      • U: removed
      • I: Enter from the current cursor location
      • :wq: Save the file and exit

Keep only the first one as pick and squash the rest as shown in the following figure

Press Esc on the keyboard and enter :wq to end vim

  1. This will then enter another VIM and enter the commit information that you will eventually merge

I ended up modifying the message like this

Exit Vim with I and Esc :wq

You’ll be successful

  1. Just upload it
git push 
Copy the code

The rebase command merges commit

git rebase --continueGit rebase --edit-todo --abort git rebase --abort git rebase --abortCopy the code

Upload code to the specified repository

How do I specify upload code to a repository?

Used for initialization

  1. Execute git init in your folder
git init
Copy the code
  1. Put everything in a folder and then
git add .
Copy the code
  1. Commit the files added in the previous step to the repository
git  commit -m "Explanatory notes to submission"
Copy the code
  1. Associate the local repository with the repository
git remote add origin https://github.com/shiyuan233.github.io/
Copy the code
  1. Using the pull command
git pull origin master
Copy the code
  1. Upload files from the local repository to the GitHub remote repository
git push -u origin master
Copy the code
  1. If the error occurs because your repository may not have initialized the readme.md file

  2. error: Your local changes to the following files would be overwritten by merge:

    This problem occurs because someone has modified the file directly on the Git server, causing the latest code from Git pull to prompt this problem. There are two solutions to this problem: Method 1: If you want to keep the code you just changed locally, pull the code from the Git server locally (the code you just changed locally will be temporarily sealed).

    git stash
    git pull origin master
    git stash pop
    Copy the code

Q&A

Git commit -m ‘XXX’ error

The reason is:

Pre-commit Hook damage

When you type git commit -m”XXX” on the terminal to commit code, the pre-commit(client) hook will run a code style check before Git types commit information. If the code does not conform to the corresponding rules, an error is reported.

Solution:

A simple and crude way

  1. Go to the hooks folder under your project’s.git folder and manually delete the pre-commit file
  2. Run the rm -rf. /git/hooks/pre-commit command to delete the pre-commit file

Add –no-verify to the command as prompted

Git commit –no-verify — m”XXX”

Third, the code changes to meet the standard before submission (recommended)

The Git commit failed. Procedure

Git commit will enter a place where you can enter your commit information if you do not have it with you

  1. Hold down the letter I to enter edit mode and enter the information you want to submit
  2. The last input:wqPress Enter to end

Version back

Go back to a version online

git reset --hard commit_id(hashGit push origin HEAD --forceCopy the code

Back to a local branch

When you just upload to the local cache you don’t upload to the repository

For example, if you add multiple commits today, such as Commit1 and COMMIT2, and you want to go back to COMMIT1, type the command

git log// Get a commit commit_id(hashGit reset --hrad commit_id // Back to a commitCopy the code

And then you push it again

Forced to cover

git push -f
Copy the code