About the git

Create a version library

  1. create

Mkdir learngit go to that directory. CD learngit displays the current directory. PWD Change this directory to a repository that Git can manage

Add the file to your Git repository. Make sure the file is in the Learngit directory or you won’t be able to find it

  1. submit

Add the file to the repository git add read.txt

Git commit -m ‘write a file’

You can add multiple times and commit once

Time machine

  1. After modifying the file

Git status check the repository status

Git diff allows you to see what changes you have made to git diff

  1. Version back

View Git logs for versions committed to the Git repository

Git log –pretty=oneline

  1. Undo modify

Git checkout — readme. TXT — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout — git checkout

Git reset –hard HEAD^

Specify the commit ID of the version you want to backtrack to, and you can go back to the version you want

Git reset -- Hard version number

Git provides a command to record each command. You can use this command to view the command history

git reflog

  1. Delete the file

rm test.txt

Needs to be deleted from the repository

git re text.txt

git commit -m 'remove text'

  1. Configure the local Git commit account (username and email)

git config --global user.name "username"

git config --global user.email "xxxx.com"

  1. Clone code from remote

git clone https://username:[email protected]/1054294965/git-test.git

Branch management

  1. Git branch

  2. Git Checkout branch name

  3. Git checkout -b dev

Git branch dev + Git checkout dev

  1. Merging branchesGit merge branch name

Merge conflicts, change in the same place, check the conflict location git status

Resolve the conflict manually, and commit the commit

  1. Pull, modify, synchronize remote branches

Git fetch — Prune Origin

Git branch -d

Git push origin –delete branch name

Synchronize the remote deprecated branch git remote Prune Origin

Change the branch name. Git branch -m Old branch name New branch name

Fix the bug

You need to fix bugs urgently, but the current dev branch is not completely fixed. Use the Stash feature to store the current work site

git stash

Then create the bugfix branch and merge the changes to the Master branch before deleting them

Switch to the dev branch to restore the state before the change

You can check out the git Stash list to see what just happened at work

Restore using two commands

The stash content is not deleted after git Stash apply is restored

After git Stash pop is restored, the stash content is deleted

If this bug exists on Dev, it needs to be fixed in the same way

You can run the cherry-pick command to copy the changes

Git cherry-pick 4c805e2

(You can also save the current workspace and then go back to your workspace, git Stash, after fixing the bugs.)

Rebase organizes locally unpushed branches into a straight line for easy viewing of historical commits

Resolve the problem of not accessing Github

Configure the hosts file juejin.cn/post/684490…

Small eggs

Attach a online learning git learngitbranching.js.org/?locale=zh_…