To generate a public key

ssh-keygen -t rsa -C "[email protected]"
Copy the code

Configuring a User Name

** Global configuration **

git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Copy the code

** Local configuration **

git config user.name "Your Name"
git config user.email "[email protected]"
Copy the code

Viewing the Submission Record

Git log –pretty=oneline git log –pretty=oneline git log

git log --pretty=oneline
Copy the code

Git a time machine

Fall back to a committed version

It is not necessary to write the full version number, just the first few digits will do, Git will automatically find it.

Of course, you can’t just write the first one or two, because Git may find multiple version numbers and never know which one it is.

/ / such as git reset - hard e655927bcfaf5c71e850abdacca1f8565fef666e (version number) / / so to write a git reset - hard e6559Copy the code

Go back to the future after rollback

Git reflog d1d1d7e HEAD@{3}: commit: fix some bugs bea1f89 HEAD@{4}: commit: A908d39 HEAD@{5}: commit: fix some bugs 2.Copy the code

Compare the difference between local and last submission

Git diff HEAD -- readme.txtCopy the code

Discard workspace modifications

Git chcekout -- fileCopy the code

Discard content added to the staging area (that is, after running Git Add)

Git reset HEAD <file>Copy the code

Branch management

Create and switch branches

Git checkout —

is the same command as git checkout —

.

Actually, switching branches is more scientific with switch. Therefore, the latest version of Git provides a new Git switch command to switch branches:

git switch -c dev
Copy the code

Switch directly to an existing branch

git switch master
Copy the code

Merging branches

git merge <name>
Copy the code

Delete the branch

git branch -d <name>
Copy the code

Push local branch to remote

Git push origin < branch name >Copy the code

Branch renaming

-m <old_name> <new_name> rename git branch to any local branch You can run the following command to rename the remote branch. The command logic is the same as: Delete the remote branch and then push the local branch to the remote repository. git push origin :<old_name> <new_name>Copy the code

The new label

Git log --pretty=oneline --abbrev-commit git log --pretty=oneline --abbrev-commit  (HEAD -> master, tag: V1.0, origin/master) merged bug fix 101 4c805e2 fix bug 101 e1e9c68 merge with no-ff f52c633 add merge cf810e4 conflict fixed 5dc6824 & simple 14096d0 AND simple b17d20e branch test d46f35e remove test.txt b84166e add test.txt 519219b git tracks changes e43a48b understand how stage works 1094adb append GPL e475afc add distributed eaadf4e wrote a readme file Git tag v0.9 f52C633 git tag -d v0.1 git tag -d v0.1 Git tag -d <tagName> git push origin :refs/tags/<tagName>Copy the code

Clone from the remote repository

Git clone -b < git address >Copy the code

Git modifies the remote repository address

  • Associate remote warehouse addresses by command line
Git remote set-url originCopy the code
  • Modify the remote address through the command line
Git remote set-url originCopy the code
  • Delete the old warehouse address first, then add the new address
Git remote rm origin git remote add originCopy the code
  • Modifying a Configuration File
> cd json/.git > vim config [core] repositoryformatversion = 0 filemode = true logallrefupdates = true precomposeunicode Fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/masterCopy the code

Fatal: No such remote ‘origin’

The set-url command is used to change the address of the remote repository. If the remote repository address has not been configured, an error will be reported:

fatal: No such remote 'origin'
Copy the code

The solution is simple, just add a remote warehouse address first

git remote add origin "xxx.git"
Copy the code

Git failed to synchronize the remote repository

Fatal: refusing to merge Suggested histories

The reason for this error is that the two branches are two different versions with different commit histories.

// You can allow unrelated historical suggestions, forced merge git pull Origin Master -- Allow-suggested -historiesCopy the code