Git repository

create

git init
Copy the code

cloning

  • Git clone path/to/repository

  • Git Clone –depth 1 path/to/repository

Git workflow

The five states of a file (Normal, Modified/Created, Staged, Submitted, and Pushed) are a progressive process, and you can switch between states forward or backward.

Undo Modified

A step back is available, in which the file is returned to its original state from modification. Note The newly created file cannot be deleted. To delete the file, run the clean command.

  • Undo single file:git checkout filepath
  • Undo full file:git checkout .

Undo creation

Delete the new file

  • View the files that will be deletedgit clean -n
  • Deletes new files that are not added to the staging area, but does not delete files specified in.gitignoregit clean -f
  • Delete contents including the newly created folder, add parameters:-d
  • Deletes a new file at the specified pathgit clean -f filepath
  • Delete new files interactivelygit clean -i
  • Deletes files not added to the staging area, including files specified in.gitignoregit clean -xf

Undo Staged

You can go back two steps to the modified or original state from temporary storage.

  1. Go back toModify the:
    • Undo single file:git reset HEAD filepath
    • Undo full file:git reset HEAD
  2. Go back toThe original:git reset --hard

Withdrawal of Submission (Submitted)

Three steps can be taken back from the commit to temporary, modified, or original state. At the same time, the number of undo can be set:

  • Undo a single commit:git reset --soft HEAD~1
  • Undo multiple submissions:git reset --soft HEAD~n

Degree of cancellation:

  1. --mixed: cancel toModify theStatus, default parameter;
  2. --soft : cancel toThe stagingState;
  3. --hard : cancel toThe originalState;

other

Modify submission comments

git commit --amend
Copy the code

Push overwrites the remote branch

git push -f
Copy the code

Branch management

The local branch

  • Display:git branch
  • Display all:git branch -a
  • Create:git branch <branchname>
  • Delete:git branch -d <branchname>
  • Switch:git checkout <branchname>
  • Modify name:git branch -m <oldBranchName> <newBranchName>

Remote branch

  • Push an existing local branch to the remote

    git push origin <branchName>
    Copy the code
  • Pull an existing branch from a remote directory to the local directory

    git fetch origin <remoteBranchName>`
    git checkout -b <localBranchName> origin/<remoteBranchName>
    Copy the code
  • Deleting a remote branch

    git push --delete origin <remoteBranchName>
    Copy the code
  • Contrast differences

    git log master... origin/masterCopy the code

Put aside modify

Sometimes you have changed a file, but need to switch to another branch temporarily, and do not want to temporarily save or commit, you can choose to shelve the current changes, the current changes are stored in the hidden area.

Note that the changes in the hidden area are independent of the branch and that the current branch’s hidden changes can be retrieved from other branches

  • Git stash save “stashMsg”

  • Check out the shelved list: git list

  • Git stash pop or git stash apply

Git Diff

Interbranch correlation

git diff --stat master origin/master
Copy the code

Git Log

  • Git Log –

    , for example, git log-2

  • Single mode

    • Brief:git log --oneline
    • Complete:git log --pretty=oneline
  • Code review: git log -p

  • Git log –stat

According to

The default format

  • --pretty=oneline: Displays only the complete Commit ID and Commit Message in one line
  • --pretty=short: Adds the display Author information
  • --pretty=full: Displays information about user Commit
  • --pretty=fuller: Adds time information

Custom format

The label

Query operation

  • List the tag git Tag

  • Git tag -l

    • Prefix matching is supported:Git tag - l * _2020 01.01.01
    • Support for suffix matching:git tag -l app_2020.*
    • Support simultaneous matching:git tag -l *_2020.*
  • Check tag details and commit information git show

  • Git tag -v

  • Git tag -n

Add tags

Lightweight tag

Store the checksum of the commit information in a file without any other information, that is, just the tag name and no other information. It cannot be created with the -a, -m, or -s options

  • Git tag

  • Looking at the lightweight tag, you can see that there is no information about the tag other than the tag name on the tag submission

    zohar@LAPTOP-FC5I09PK:~/zoharyips.github.io$ git show lig_weight_tag
    commit c819f38d0ded8411d0c427896530f83f10b3639c (HEAD -> master, tag: lig_weight_tag, origin/master, origin/HEAD)
    Author: zoharyips <[email protected]>
    Date:   Wed Sep 2 18:39:20 2020 +0800
    
        fix a bug
    
    diff --git a/_wiki/mysql-skills.md b/_wiki/mysql-skills.md
    index e67329f..6f00866 100644
    --- a/_wiki/mysql-skills.md
    +++ b/_wiki/mysql-skills.md
    @@ -136,7 +136,9 @@ prism: trueSELECT ifnull ((SELECT data FROM [table] GROUP BY data DESC LIMIT 1, 1), null) AS max; ` ` `Copy the code

Note the label

  • Git tag -a

    -m

  • Git push origin

configuration

Check the configuration

git config --list {--local | --global | --system}

localGlobal: indicates all the warehouses of the current user. System: indicates all the users of the systemCopy the code

Color output

git config color.ui true
Copy the code

Single row shows

git config format.pretty oneline
Copy the code

Cancels automatic newline conversion

git config --global core.autocrlf false
git config --global core.safecrlf true
Copy the code

User configuration

git config {--local | --global | --system} user.name 'username'
git congig {--local | --global | --system} user.email 'emailAddress'
git config {--local | --global | --system} credential.helper store # Save user name and password
git config --system --unset credential.helper # Clear user name and password
Copy the code

The editor

git config --global core.editor <editorName>
Copy the code