Pro Git Learning Notes


Pro Git Learning Notes

Document address: Pro Git
Address: PRO GIT Learning Notes

1. Git Start

Configuration before initial Git run

User information

git config --global "your user name"
git config --global "your email address"

text editor

Set the default text editor:git config --global core.editor emacs

View configuration information

git config --list

2. Git Foundation

Create a Git repository

Initialize a new warehouse in the working directory

git init

Cloning Existing Warehouse

git clone url

urlbranchsshandhttpsTwo, recommendedssh

Check the current file status

git status

Tracking up-to-date documents

Git add file name or *.js/css/html... or.

Ignore documents that you do not want to submit

cat .gitignore

View pending and non-pending updates

git diff
git diff --cached

Submit update

Git commit-m "Submit Remarks Information"

Skip the use of temporary storage areas

Git commit-a "Submit Remarks Information"

Use when submittinggit commit -aThe tracked temporary files are submitted together and skipped.git addThe step is to merge the two commands.

remove file

git rm

Remove and delete the specified files in the working directory from the list of tracked files. Usegit statusView the trace file list, and then use itgit rmAccurate removal.

Forced Removal Usegit rm -fBut it is not recommended.

Delete files from remote repositories using:

Git RM -- Cached File Name /*. File Suffix / Folder...

move file

For renaming or moving files, you can use:

git mv file_from file_to

View submission history

git log
git log -p -2

-pOption Expansion Displays Content Differences for Each Submission-2Show the last two updates.

Word-level comparison, using:

git log -p -U1 --word-diff

This command is less used in code checking and more used in text editing.

Display summary information using:

git log --stat

Other useful commands:

--prettyOptions can specify that the submission history is displayed in a completely different format than the default format, usingonelinePlacing each submission on a single line is very useful when the number of submissions is large:

git log --pretty=online

formatRecord formats to be displayed can be customized:

git log --pretty=format:"%h - %an, %ar : %s"

Common Format Occupant Writing and Its Significance

option Explain
%H Submitted object(commit) Complete hash string
%h Short hash strings for submitting objects
%T Tree objects (tree) Complete hash string
%t Short hash strings for tree objects
%P Parent object(parent) Complete hash string
%p Short hash strings for parent objects
%an Author (authorName
%ae Author’s e-mail address
%ad Author’s revision date (available)-date=Option customization format)
%ar How long ago was the date of the author’s revision displayed?
%cn Submitter(committerName
%ce Submitter’s e-mail address
%cd Date of submission
%cr How long ago was the submission date displayed?
%s Submission instructions

Adding simple graphics represented by ASCII strings

git log --pretty=format:"%h %s" --graph

Options supported by the GIT log command

option Explain
-p Display the differences between each update in patch format.
--word-diff Pressword diffThe format shows the difference.
--stat Display file modification statistics for each update.
--shortstat Display only--statThe last row number modification adds removal statistics.
--name-only Display the list of modified files only after submitting information.
--name-status Displays a list of new, modified and deleted files.
--abbrev-commit Display onlySHA-1The first few characters, not all40A character.
--relative-date Shorter relative time display (e.g.2 weeks ago”)。
--graph displayASCIIHistory of branch merging in graphical representation.
--pretty Use other formats to display historical submission information. Available options includeonelineshortfullfullerandformat(followed by the specified format).
--oneline --pretty=oneline --abbrev-commitSimplified usage.

Limit output length

A time-bound order--sinceand--until

git log --since=2.weeks

search criteria

  • --authorDisplay the submission of the designated author
  • --grepSearch for keywords in submission instructions
  • --all-matchSubmission that satisfies both options search criteria

Other commonly used similar options

option Explain
-(n) Show only the nearestnArticle submission
--since, --after Shows only submissions after the specified time.
--until, --before Show only submissions before the specified time.
--author Only the submissions related to the specified author are displayed.
--committer Only the submissions associated with the specified submitter are displayed.

Specific examples:

git log --pretty="%h - %s"  --author=gitster --since="2018-10-01" \ --before="2008-11-01" --no-merges -- t/


Modify last submission

git commit --amend

Cancellation of temporary documents

Git reset HEAD file name

Cancel the modification of the document

This order is used with caution.

Git checkout -- File name

Use of remote warehouse

View the current remote library

git remote

Display the corresponding clone address

git remote -v

Add remote warehouse

git remote add [shortname] url

Grabbing warehouse information

git fetch [shortname]

Grabbing data from remote warehouse

This command fetches data from the remote warehouse to the local location

git fetch [remote-name]

Grabbing Update Data of Cloned Remote Warehouse

git fetch origin

fetchCommands simply grab data from remote warehouses locally and do not automatically merge into the current branch of work

Recommended commands to pull remote warehouse data and merge data

git pull

Push data to remote warehouse

git push origin master

View remote warehouse information

git remote show [remote-name]

Delete and rename remote warehouse

Rename remote warehouse

git remote rename
git remote rename vue react

Remove remote warehouse

git remote rm vue


Display existing labels

git tag

Setting Conditions for Search

git tag -l "v1.4.2.*"

new label

Lightweight label

git tag

Annotated labels

git tag -a
git tag -a v1.4 -m "my version 1.4"

View version information for the corresponding label

git show v1.4

Signature label

git tag -s
git tag -s v1.5 -m "my signed 1.5 tag"

Validation tag

git tag -v [tag-name]
git tag -v v1.4.2.1

Later tagging

Forget labeling, just keep up with the checksum of the corresponding submitting objects when labeling.

git tag -a v1.2 9fceb02

Share Tags

git push origin v1.5

Push all new local labels at once

git push origin --tags

Skills and tips

Automatic completion

windowsContinuous press under systemTabkey

Git command alias

git config --global commit
git config --global status

Git bifurcation

New Test Branch

git branch testing

Switch to the testing branch

git checkout testing

Branch Construction and Merger

Merge the above two commands

git checkout -b testing

Git restores the contents of the working directory to a snapshot of the submitting object it points to when a branch is detected. It automatically adds, deletes, and modifies files to ensure that the contents of the directory are exactly the same as they were submitted at the time.

Merge submissions

git merge
git checkout master
git merge hotfix

Delete working branches

git branch -d hotfix

Merger of Branches

View conflicts git status

Calling Visual Merge Tools to Resolve Conflicts

git mergetool

Branch management

View information about the last submission object for each branch

git branch -v

See which branches have been merged into the current branch

git branch --merged

View branches that have not yet been merged

git branch --no-merged

Workflow of Branch Development

Long term branch

Characteristic branch

Remote Branch

Synchronize data from remote server to local

git fetch origin 

Push local branches

git push origin master

New branches are differentiated on the remote branches:

git checkout -b serverfix origin/serverfix

Tracking remote branches

git checkout -b sf origin/serverfix

Delete remote branches

Derivation of Branches

Integrated branching method

git merge
git rebase

History of distinguishing a feature branch from a feature branch

git rebase --onto master server client

git checkout master
git merge server

Derivative risk

Once the submission objects in the branch are published to the public warehouse, it is important not to derive from the branch.

Git on the server


Git can transmit data through four main transport protocols: local protocol, SSH protocol, Git protocol and HTTP protocol.

Deploy Git on the server

git clone --bare my_project my_project.git

Move bare warehouse to server

To be continued

Recommended Today

What black technology does the real-time big data platform use behind the glory of the king?

Hello everyone, I’m Xu Zhenwen. Today’s topic is “Tencent game big data service application practice based on Flink + servicemesh”, which is mainly divided into the following four parts: Introduction to background and Solution Framework Real time big data computing onedata Data interface service onefun Microservice & servicemesh 1、 Introduction to the solution framework and […]