Git Git

Before listing common commands, let’s briefly review git object types

Git object types

Block (blob)

Each version of a file represents a block (blob-binary large object). A BLOB holds the data of a file, but not the metadata of the file, such as the file nameCopy the code

Directory tree (tree)

A directory tree object represents a layer of directory information. It records bloB identifiers, pathnames, and some metadata for all files in a directory.Copy the code

(commit)

A commit object holds metadata for every commit in the version, including author, commit, and commit date. Each submission object points to a directory tree object.Copy the code

Label (tag)

A label object assigns an arbitrary, human-readable name to a particular object. Usually a commit object.Copy the code

Common commands

git init

Git /objects/ The directory in which all Git objects are stored, is initially empty

git init

git cat-fileQuerying Object Data

  1. Git cat-file -h Check for help
  2. Git cat-file -t [object name] Check the object type
  3. Git cat-file -p git cat-file -p

git logSee the history

  1. The git log [-p | — patch] [number] – introduced by committing a difference [number recent submission]
  2. Git log –stat [-number
  3. Git log –graph [-number] displays branch and merge history in a graph

git stashStorage changes

Stash keeps unfinished changes on a stack and can then be reapplied at any time

  1. Git Stash list Looks at all the records on the stash stack
  2. Git Stash push -m ‘your desc’ adds records to the stack
  3. Git stash [pop | apply] [stack name – stash @ {0}]

Pop is fetching data from the stack

Apply just uses, and the records in the stack remain

git-reset

You can use this when you want to undo a COMMIT

  1. git reset commithashUndo to presentcommithashThe submission of
  2. git reset HEAD^Undo current commit

The update code is still in place. If you want to undo it completely, add –hard will undo the add as well. If you just want to modify the commit, use git commit –amend.

git cherry-pick

Git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick You can move the code you just committed to branch A. Git reset –hard HEAD^

git ls-files -sDisplay file Information

Displays information about indexes and files in the working tree

git tag

Create, list, delete, or validate tag objects that use GPG signatures

git rev-parse

  1. Git rev-parse looks for hash values based on the object name prefix

Usage scenarios

Change the code to the wrong branch

In the case of multi-branch programming, it is common to add code to the wrong branch and then get an error when trying to cut back to the correct branch. Here’s what you can do

After cutting back to the branch, pull the Git Stash pop out of the stashCopy the code

Thank you

Welcome comments correction! Content continues to be updated!