1 Git Internal principles

1.1 the Git object

1.1.1 Blob object

Blob objects are file snapshots, which are stored in a.git/objects directory for Git staging. Git /objects creates empty pack and INFO subdirectories by default. The core of Git is a simple key-value data store, which can be understood as file directories and files as keys, and file contents in the directory as corresponding values.

Run the following low-level command to insert content into the Git database. The echo ‘content’ text output content, | for pipe, namely after the output of the previous command as a command input. -w means to write to the database, –stdin means to read from the pipe. Git hash-object –stdin reads the content from the pipe, and then specifies the -w option to write it to a git database.

echo 'content' | git hash-object -w --stdin
d95f3ad1...
Copy the code

D95f3ad1… Git /objects is the sha-1 checksum of blob objects, represented in directories. Git /objects as the first two bits for naming subdirectories and the remaining 38 bits for file names. The find command is used to find files in the specified directory. -type indicates the specified file type, and f indicates that the file type is common.

find .git/objects -type f
.git/objects/d9/5f3ad1...
Copy the code

D95f3ad1… To obtain the value of the key in Git database, run the following command. -p indicates that the content type is automatically determined and displayed in a friendly format. You can also specify the -t option to view the object type.

git cat-file -p d95f3ad1
content
Copy the code

It may be complicated to write content to Git database in echo mode, but you can also write file content to Git database. Write the contents of the readme.md file to the database as follows.

git hash-object -w readme.md
Copy the code

1.1.2 Minimalist version control

Create a new file and store its contents to the database.

echo 'hello world' > readme.md
git hash-object -w readme.md
3b18e512...
Copy the code

Write the new content again and save it to the repository.

echo 'hi git' > readme.md
git hash-object -w readme.md
2984e649.Copy the code

Take a look at database writes temporarily.

find .git/objects -type f
.git/objects/29/84e649. .git/objects/3b/18e512.Copy the code

Control file content to the first version.

git cat-file -p 3b18e512 > readme.md
cat readme.md
hello world
Copy the code

The control file content is the second version.

git cat-file -p 2984e649 > readme.md
cat readme.md
hi git
Copy the code

1.1.3 Tree object

Only the contents of the files are saved in the database above, the file names are not saved, and it is not practical to remember the SHA-1 checksum for each version. A Tree object is a Tree object. A Tree object contains one or more Tree object records. Each record has a SHA-1 pointer to a data object (blob object) or subtree object, and the corresponding schema, type, file name, or directory name.

A tree object might have the following contents. Master ^{tree} represents the tree object to which the latest commit of the master branch is directed. Readme. md and file. TXT are both data objects, dist is a subtree object.

git cat-file -p master^{tree}
100644 blob a906cb12...      readme.md
100644 blob 8f941322...      file.txt
040000 tree 99f1a699...      dist
Copy the code

View subtree objects.

git cat-file -p 99f1a699
100644 blob 47c63436...      index.html
Copy the code

The internal data stores are as follows.

Readme.md --> blob/tree -- file.txt --> blob -- dist --> tree -- index.html --> blobCopy the code

Git creates tree objects based on the state of the staging area, so some changes or files need to be added to the staging area. To modify the staging, run the following command. If the file name is not in the staging area, specify the –add option. — cacheInfo adds the specified information to the staging area, including the file mode, sha-1 checksum, and file name, and the sha-1 checksum must be full. The following command can be roughly summarized as the staging data object 3b18e512… The file mode is 100644 and the file name is readme.md.

git update-index --add --cacheinfo 100644 \
3b18e512... readme.md
Copy the code

View the status details of the staging area.

git ls-files -s
100644 3b18e512... 0       readme.md
Copy the code

Write the contents of the staging area to a tree object by running the following command. Of which 7394 b8cc… Sha-1 is the checksum of the tree object.

git write-tree
7394b8cc...
Copy the code

View tree object contents and database writes

git cat-file -p 7394b8cc
100644 blob 3b18e512...    readme.md
find .git/objects -type f
.git/objects/73/94b8cc...
Copy the code

1.1.4 Subtree Objects

After creating a tree object, create a new tree object.

git update-index --add --cacheinfo 100644 \
2984e649. readme.mdCopy the code

Git creates data objects from the contents of the new files and writes them to the database. The sha-1 checksum, file mode, and file name are added to the staging area.

echo 'file' > file.txt
git update-index --add file.txt
Copy the code

The staging area now includes the new version of readme.md and a new file file.txt, which writes the staging area contents again to a new tree object.

git write-tree
e331c9c2...
Copy the code

View the staging area.

git ls-files -s
100644 f73f3093... 0       file.txt
100644 2984e649.0       readme.md
Copy the code

Now there are two tree objects in the database. And e331c9c2… Run the following command to add the first tree object to the staging area. –prefix indicates that an existing tree object is added to the staging area as a subtree, dist is the subdirectory name.

git read-tree --prefix=dist 7394b8cc
Copy the code

Write a new tree object again.

git write-tree
ccf028c6...
Copy the code

View the new tree object.

git cat-file -p ccf028c6
040000 tree 7394b8cc...    dist
100644 blob f73f3093...    file.txt
100644 blob 2984e649. readme.mdCopy the code

1.1.5 Submit objects

There are now three tree objects… , e331c9c2… And ccf028c6… , respectively trace different file snapshots. To reuse these snapshots, remember the three SHA-1 checksums above. It is also not known who saved the snapshots, when they were saved, or why, which leads to the commit object.

Run the following command to create a commit object. Where ‘A’ is the commit information, and 7394b8cc is the tree object to which the commit object points after creation.

echo 'A' | git commit-tree 7394b8cc
f0dcf2c3...
Copy the code

View the submitted object f0dCF2C3.

git cat-file -p f0dcf2c3
tree 7394b8cc...
author ...
committer ...

A
Copy the code

Create a commit object based on the other two tree objects, where e331C9c2 represents the checksum of the tree object, -p represents the specified parent commit object, and f0dCF2C3 represents the checksum of the parent commit object.

echo 'B' | git commit-tree e331c9c2 -p f0dcf2c3
5d3d89ce...
echo 'C' | git commit-tree ccf028c6 -p 5d3d89ce
b41c0107...
Copy the code

View the submission object 5D3D89CE.

git cat-file -p 5d3d89ce
tree e331c9c2...
parent f0dcf2c3...
author ...
committer ...

B
Copy the code

At this point, the internal Git relationship is roughly as follows, but the commit history cannot be viewed in Git log for the time being because there is no branch yet.

                                   readme.md (2984e649Git) - > blob (hi) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | | C/(b41c0107) -- - > tree (ccf028c6) - dist - > tree B8cc (7394) - readme. Md (3 b18e512) - > blob (hello world) - | -- - | | \ | | | file. TXT (f73f3093) -- - > blob (file) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | | | | | | | B (5 d3d89ce) - > tree (e331c9c2) -- readme. Md (2984e649) --> blob (hi git) --------------------------------|--| | | \ | | | file.txt (f73f3093) --> blob (file) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | | | | A (f0dcf2c3) -- - > tree (7394 b8cc) -- the readme. Md (3 b18e512) - > blob (hello world) ---------------------------------|Copy the code

1.1.6 Object Storage

The steps for Git data object storage are as follows. All Git objects are stored this way, except for the type identifier. The headers for the other two types of objects start with the string COMMIT or tree instead of blob. While the content of a data object can be anything, the content of a submission object and a tree object have their own fixed formats.

  • Read file contents to object typeblobConstructs a header information as the beginning, concatenates the header information with the original file content, denoted ascontent
  • To calculatecontenttheSHA-1So the checksum, the length is zero40Hashes of hexadecimal characters
  • Take the first two hash values as file directories, and the rest38As the file name
  • rightcontentperformlibCompress, get the new binary content and store it in a file

1.2 the Git reference

You can run Git log b41C0107 to view the commit history, where B41C0107 is the partial checksum of commit record C. But looking at the commit history you still need to remember the partial checksum of a record, and the problem is solved if you store the checksum in a file with a simple name, which is called a reference. The reference files are stored in the. Git /refs directory.

1.2.1 Branch References

To create a branch reference, simply add the branch name in the.git/refs/heads directory with the checksum of a commit. Git provides a more secure command, update-ref, to write the full checksum corresponding to b41C0107 to the master file in Git /refs/heads.

git update-ref refs/heads/master b41c0107
Copy the code

View the contents of the master branch file below. It also confirms that the branch is a mutable pointer to the submitted object.

cat .git/refs/heads/master
b41c0107...
Copy the code

1.2.2 HEAD reference

HEAD is a symbolic reference to the current branch, or a branch that points to another reference.

Running Git branch dev creates a dev branch, but looking at the contents of the dev reference file gives the full checksum, which is obtained via HEAD.

Git /refs/heads: Git /refs/heads: Git /refs/heads: Git /refs/heads

git branch dev
cat .git/refs/heads/dev
b41c0107...
Copy the code

View the HEAD content.

cat .git/HEAD
ref: refs/heads/master
Copy the code

The following represents pointing the current HEAD to the dev branch.

git symbolic-ref HEAD refs/heads/dev
Copy the code

1.2.3 Label Reference

Labels include lightweight labels and note labels.

A lightweight label is a fixed reference to a commit object.

The annotation tag points to a tag object, which holds a reference to a submitted object.

Run the following underlying command to create a lightweight label v1.8.5.

git update-ref refs/tags/v18.. 5 HEAD
Copy the code

View the lightweight label V1.8.5. The following lightweight label V1.8.5 points to commit B41C0107.

cat .git/refs/tags/v18.. 5
b41c0107...
Copy the code

Create the annotation label v1.8.6.

git tag -a v18.6. HEAD -m 'message'
Copy the code

View the complete checksum of the label object (4740eA0B).

cat .git/refs/tags/v18.6.
4740ea0b...
Copy the code

View the contents of label object 4740EA0B, where Object indicates the submission record pointed to.

git cat-file -p 4740ea0b
object b41c0107...
type commit
tag v18.6.
tagger ...

message
Copy the code

1.2.4 Remote Reference

A remote reference is a local repository that holds pointing information about branches in the remote repository.

Remote references are read-only, and you can git checkout to a remote reference, but Git does not point a HEAD reference to that remote reference.

Remote references are typically kept in the refs/ Remotes directory and are updated when interacting with remote repositories.

If the remote repository repo contains branches dev and master, add remote repository Origin and pull.

git remote add origin https://github.com/username/repo.git
git fetch origin
...
From https://github.com/username/repo
 * [new branch]      dev       -> origin/dev
 * [new branch]      master     -> origin/master
Copy the code

Git /refs/remotes/origin

find .git/refs/remotes/origin -type f
.git/refs/remotes/origin/dev
.git/refs/remotes/origin/master
Copy the code

View the master branch of the remote repository, where 90edC78e is the last committed checksum pointed to by the master branch.

cat .git/refs/remotes/origin/master
90edc78e...
Copy the code

1.3 package files

Git keeps track of a file with thousands of lines of code, and if you change a single line of code in that file, Git saves the entire file as a data object (BLOB). The original object and the modified object are called loose objects.

Git stores objects on disk in a loose object format and from time to time packs objects into a single package file (binary) to save space and improve efficiency. Git is packaged when there are too many loose objects in the repository or when git gc is performed or pushed to a remote server.

Git GC stores the complete contents of a file as a data object, and the differences from the complete contents as another data object.

1.3.1 packaging

Initialize an empty warehouse repo, add a readme.md file of about 10KB, temporarily save the readme.me file size (10311 bytes), commit this change.

git add readme.md
git ls-files -s
100644 767466fd... 0       readme.md
git cat-file -s 767466fd
10311
git commit -m 'A'
Copy the code

The readme.md file also holds and views the file size (10319 bytes) after appending some content to the end.

echo 'message' >> readme.md
git add readme.md
git ls-files -s
100644 f08cfd3e... 0       readme.md
git cat-file -s f08cfd3e
10319
git commit -m 'B'
Copy the code

Git /objects contains 6 new objects, 2 tree objects, 2 commit objects, and 2 data objects.

find .git/objects -type f
.git/objects/76/7466fd... .git/objects/f0/8cfd3e... .Copy the code

Run git GC to package loose objects and view the objects under.git/ Objects. It contains an.idx index file and a.pack file. The package file contains the contents of all objects removed from the Git database, and the index file contains the offset information of the package file, which can be used to quickly locate any specified object.

Note that most objects are packaged into package files, but Git keeps dangling data objects, that is, data objects that are not referenced by any committed record.

git gc
.git/objects/info/packs
.git/objects/pack/pack-3575...a060.idx
.git/objects/pack/pack-3575...a060.pack
Copy the code

Run the following underlying command to view the contents of the index file. There are six objects, and each line contains the object’s SHA-1 checksum, type, file size, package file size, package file offset, and possibly depth, base SHA-1 checksum.

Note that the second version of readme.md, f08cfd3e, holds the full content, while the first version, 767466fd, holds the difference, because Git requires quick access to the latest version in most cases.

git verify-pack -v .git/objects/pack/pack-3575...a060.ind
f08cfd3e... blob   10319 2561 265
767466fd... blob   7 18 2921 1f08cfd3e... .Copy the code

1.3.2 reference

The other thing the git GC does is package references from the git/refs directory into files. If the current version library contains the following branches and labels:

find .git/refs -type f
.git/refs/heads/master
.git/refs/remotes/origin/master
.git/refs/tags/v18.. 5
.git/refs/tags/v18.6.
Copy the code

Git /refs will be moved to the. Git/Packed -refs file. Where ^ indicates that the label on the line above it is an annotation label, and the line in ^ is the checksum of the submitted record that the annotation label points to.

Git does not modify the Packed -refs file, but creates a new reference file in the.git/refs directory. If Git wants to get the latest SHA-1 checksum of a reference file, it first looks for the specified reference file in the.git/refs directory, and then in the Packed -refs file.

cat .git/packed-refs
ceb21368... refs/heads/master
040db796... refs/remotes/origin/master
ceb21368... refs/tags/v18.. 5
9dcb07d9... refs/tags/v18.6.
^ceb2136...
Copy the code

1.4 Reference Specifications

After associating the local repository with the remote repository, view the. Git /config file. It specifies the name of the remote repository, the URL, and the reference specification to fetch. Formats such as < SRC >:< DST > are called reference specifications, < SRC > represents a reference in a remote repository, < DST > represents a local location for a remote reference, and + indicates that a reference is forced to update if fast forward is not possible.

git remote add origin https://github.com/username/repo.git
cat .git/config
...
[remote "origin"]
        url = https://github.com/username/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
Copy the code

By default, running git fetch will fetch all references from the remote repository’s refs/heads directory and write them to the local refs/remotes/ Origin directory.

git fetch origin
...
From https://github.com/username/repo
 * [new branch]      dev         -> origin/dev
 * [new branch]      master      -> origin/master
find .git/refs/remotes/origin -type f
.git/refs/remotes/origin/dev
.git/refs/remotes/origin/master
Copy the code

1.4.1 expand

After the local repository retrieves the master branch of the remote repository, view the commit history of the branch. The following three commands equivalence, and eventually will be expanded for the refs/remotes/origin/master.

git log origin/master
git log remotes/origin/master
git log refs/remotes/origin/master
Copy the code

1.4.2 obtain

Get only the master branch of the remote repository REPO, not all branches, modified to the following reference specification.

fetch = +refs/heads/master:refs/remotes/origin/master
Copy the code

Get multiple remote branches. The following indicates that only the remote master and dev branches are retrieved.

fetch = +refs/heads/master:refs/remotes/origin/master
fetch = +refs/heads/dev:refs/remotes/origin/dev
Copy the code

1.4.3 Namespaces

Push the local Master branch to the remote repository feat/ Master branch

git push origin master:feat/master
Copy the code

Obtain only the dev branch of the remote repository and the branch under the namespace feat, and change them to the following specifications.

fetch = +refs/heads/master:refs/remotes/origin/master
fetch = +refs/heads/feat/*:refs/remotes/origin/feat/*
Copy the code

1.4.4 Forced Update

If the remote warehouse repO has A master branch, users A, B, and C are all associated and fetch the latest changes.

User A forces the submission history irrelevant to the original history to master.

The git/config configuration is as follows.

fetch = +refs/heads/*:refs/remotes/origin/*
Copy the code

Git /config: delete and disable forcible update.

fetch = refs/heads/*:refs/remotes/origin/*
Copy the code

User B fetched the modification in the fetch remote repository. Forced Update means that the master commit history is forcibly updated.

git fetch origin ... +... master -> origin/master (forced update)Copy the code

User C gets a remote warehouse change where the pull for the master branch is rejected because its commit history cannot be fast-forwarded.

git fetch origin
...
 ! [rejected]        master     -> origin/master  (non-fast-forward)
Copy the code

1.5 Restoration and Removal

1.5.1 Data Recovery

If the commit history of a library is as follows, the current HEAD points to the master branch.

A —— B —— C —— D —— E <-- master <-- HEAD
Copy the code

Rollback master branch to commit record C.

git reset --hard HEAD^^
Copy the code

If you want to switch the master branch commit record to E, run git reflog to check commit E in the reference log.

git reflog
...
329e7f4 HEAD@{1}: commit: E
Copy the code

To switch master to commit E, run git reset –hard HEAD@{1}.

For some reason, commit E may not be in the reference log reFLOg, and there is no reference to commit E.

To simulate this scenario, first point master at commit C and then delete the referenced logs in the.git/logs directory. Running git reflog at this point will produce no output.

rm -r .git/logs
Copy the code

Git checks database integrity by running the following command, where –full displays all objects that were not referred to by other objects and the checksum for E.

git fsck --full
...
dangling commit 329e7f4...
Copy the code

1.5.2 Disk Space

Run the following command to check the number of objects in the Git database and disk consumption.

git count-objects -v
count: 3
size: 4
in-pack: 6
packs: 1
size-pack: 132
prune-packable: 2
garbage: 0
size-garbage: 0
Copy the code

The print parameters are described as follows.

  • count: The number of loose objects
  • size: Disk space occupied by loose objects, toKiBFor the unit
  • in-pack: The number of all objects in the package file, i.e.git/objects/packDirectory under all to.idxIs the number of objects stored in the suffix file
  • packs: Number of package files, i.e.git/objects/packDirectory to.packIndicates the number of files with suffix names
  • size-pack: Disk space occupied by package files toKiBFor the unit
  • prune-packable: The number of loose objects in the package file, rungit prune-packedCan be deleted, rungit prune-packed -nDisplays the object to be deleted
  • garbage: The number of junk files that are neither valid loose objects nor valid packages
  • size-garbage: The disk space occupied by garbage files toKiBFor the unit

1.5.3 Removing an Object

If someone to Git repository added a particularly large files, and then removed from the project, but due to the Git commits history tracking to this file, or may at any time by submitting a history restore this file, each time you run the Git clone cloning project history, will be forced to download this file, every time is caused by the clone is very time-consuming.

Therefore, every commit record must be overwritten starting with the tree object that originally referenced the file. This destroys the commit history, and it is best for someone else to run Git pull –rebase when pulling the record.

Because the history line is too long, you do not know what the file is. You can find out the file in the following way.

First, run git GC to package the objects in git database and view the files in.git/objects/pack.

git gc find .git/objects/pack -type f .git/objects/pack/pack-3aa8... a09e.idx .git/objects/pack/pack-3aa8... a09e.packCopy the code

Run the following command to view the index file content and sort it. The first line outputs the contents of the index file, which is piped to the next line. Sort Sort the pipe input. -n indicates sorting by numeric size, and -k 3 indicates sorting by the third column of the content. Tail-3 indicates the last three lines of the displayed content.

git verify-pack -v .git/objects/pack/pack-3aa8... a09e.idx \ | sort -n -k3 \
  | tail -3
bc65c0d9... commit 206 141 437
c4a96707... commit 206 140 1145
072e320f... blob   7407405 6594320 1978
Copy the code

The data object 072E320f in the above list occupies about 7M space. Run the following command to find the corresponding file name based on the checksum. Git rev-list –objects –all check whether the checksum of all Git objects is related to the file name, enter the pipe character, grep the checksum of all Git objects is 072e320f, and finally find the file.

git rev-list --objects --all | grep 072e320f
072e320f... file.zip
Copy the code

Run the following command to check which committed records have changed this file, where –branches indicates the scope of all branches of the current repository.

git log --oneline --branches -- file.zip
9db12cc (HEAD -> master) remove file.zip
52bd5ce add file.zip
Copy the code

Run the following command to erase the commit history, 52bd5CE ^.. HEAD indicates that 52BD5CE and subsequent submissions will be erased and overwritten.

git filter-branch -f --prune-empty --index-filter 'git rm -f --cached --ignore-unmatch file.zip'52bd5ce^.. HEADCopy the code

Run the following command to thoroughly clean up the commit history and reanalyze and package the repository.

  • The erase command generates a backup by default, essentially saving a reference to the latest commit in the original commit history,rm -rfdelete.git/refs/originalSubdirectory reference
  • Trim all reference logs up to the current point in time
  • Print out unreachable objects
  • Turn all unreachable objects in a package into loose, unpackaged objects instead of remaining in the old package. If a newly created package makes some existing packages redundant, delete redundant packages
  • Spend more time more aggressively tuning the repository and prune loose objects prior to the current point in time
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git fsck --full --unreachable
git repack -A -d
git gc --aggressive --prune=now
Copy the code

2 Gitk

Gitk is a graphical visualization tool built into Git that includes a commit history map, information about each commit, and files in the version tree.

Run gitk in the root directory of the Git repository to open the following visual interface. It mainly includes four areas: menu bar A, submission history B, submission information C and version tree file D.

2.1 the menu bar

2.1.1 the File

  • Update: update, after the command line operation of the warehouse, the changes are reflected ingitkUpdate the reference and display the old and new differences. Generally run after rebasing, you can compare the previous branch head with the new branch head
  • Reload: reload
  • Reread references: Reread quote
  • List references: list of references, including labels and branches. Among themFilterWithin the*Represents all references,*masterThe screeningmaster,remotes/origin/masterbranch

  • Start git guiOpen:git guiVisualization tool
  • Quit: quit

2.1.2 Edit

Preferences include common Settings, color, and font Settings. Caution Some Garbled Characters may appear in the submission information area C, and you need to add the following characters to git/config:

[gui]
    encoding = utf-8
Copy the code

  • Maximum graph width (lines): Maximum graphic width (line)
  • Maximum graph width (% of pane): Maximum graphic width (percent pane)
  • Show local changes: Displays local changes
  • Auto-select SHA1 (length): Automatic selectionSHA-1Checksum (length)
  • Hide remote refs: Hides the remote reference
  • Tab spacing: Label spacing
  • Display nearby tags/heads: Displays the most recent label or reference
  • Maximum # tags/heads to show: Maximum number of labels or references to be displayed
  • Limit diffs to listed paths: Limits the difference between listing paths
  • Support per-file encodings: Supports file encoding
  • External difftoolExternal:difftool
  • Web browser:WebThe browser
  • Use themed widgets: Use the widget theme

2.1.3 the View

You can set quick query views to filter query records based on query conditions and compare the differences between two views. The added view can be edited or deleted.

  • View Name: View name
  • Branches & tags: Branch or label name, separated by Spaces, optionally including all referencesAll refs, all local branchesAll (local) branches. All labelsAll tags, all remote trace branchesAll remote-tracking branches
  • Commit Info: Submit information, including authorAuthor, the submitterCommitterSubmit informationCommit Message, optionally including matching all submission information criteriaMatches all Commit Info citeria, did not match all submission information conditionsMatches no Commit Info crteria
  • Changes to Files: Changes to file contents, including fixed stringsFixed String, regular expression matchingRegular Expression
  • Commit Dates: Submission time, including start timeSinceAnd end timeUntil
  • Limit and/or skip a number of revision (positive integer): Displays a fixed number of commit logs, and a certain number of logs can be skipped from the beginning
  • Miscellaneous options: Other options, including sorting by timeStrictly sort by date, mark the branch sideMark branch sides, restrict the first parent submissionLimit to first parentBrief HistorySimple history, can also be customizedgit logThe parameters of the
  • Enter files and directories to include, one per line: Contains files and directories, one in a row

2.1.4 Help

Gitk help includes gitk introduction, shortcuts.

2.2 Submission History

The submission history includes the submission information, who submitted it, and when it was submitted.

Clicking on a different submission history is highlighted as a blue background, and the sha-1 checksum of the submission is displayed at the bottom. Each click is recorded by GITK, the left and right arrows toggle the submission record, and Row is the number of rows and total number of submitted rows currently clicked.

The submission information highlights the local branch, the label, and the remote trace branch. The local branch has a green background, the branch pointed to by the HEAD is in bold black, the label has a yellow background, and the remote trace branch has an orange background.

Find Displays the submitted records that meet the search criteria.

2.2.1 Branch right-click menu

  • Check out this branch: Switch to this branch, that isHEADPoint to this branch
  • Rename this branchRename this branch
  • Remove this branch: Deletes the branch
  • Copy branch name: Copy the branch name

2.2.2 Record the right-click menu

  • Create tag: Create a label
  • Copy commit reference: Copy this submission brief information, including7positionSHA-1Checksum, submission information and submission time (mm/DD)
  • Write commit to file: Exports detailed submission information, including modification content, to a file
  • Create new branch: Creates a new branch
  • Cherry-pick: Pick this submission
  • Reset master branch to hereReset:masterBranch to this submission, includingSoft,MixedandHard, includingHardWill reset the working directory and staging area,MixedWill reset the staging area,SoftUndo only the commit after this commit

  • Mark this commit: marks the submission. The marked submission has a black border. Note that there can only be one marked submission
  • Revert this commit: Restores the commit, that is, generates a new commit to undo the changes made to the commit

2.2.3 Right-click menu after marking

Once one submission is marked, the remaining submissions open up a partial right-click menu.

  • Return to mark: Jumps to the marked commit
  • Find descendant of this and mark: Finds the most recent common descendant of the current and marked commits
  • Compare with marked commit: Compares this commit with the marked commit, which is different fromdiff
  • Diff this -> markedcommit:diffThis commit and the marked commit
  • Diff marked commit -> this:diffTagged commit and this commit

2.2.4 Right-click the menu after selection

After selecting a submission, right-click other submissions to open part of the right-click menu.

  • Diff this-> selected:diffThis commit and the selected commit
  • Diff selected -> this:diffThe selected commit and this commit
  • Make patch: combines this submission with the selected submissiondiffTo generate apatchfile

2.2.5 Submitting a Historical Query

At the bottom, the list of query types is displayed after commit.

  • containing: contains the following range parameters
  • touching paths: File path
  • adding/removing string: Modification includes adding or deleting strings
  • changing lines matching: Indicates the number of modified lines

Query mode.

  • Exact: Exact matching
  • IgnCase: Ignore case
  • Regexp: Regular expression

Query scope.

  • All fileds: All ranges
  • Headline: The title of the submission message
  • Comments: Indicates the content of the submitted information
  • AuthorAuthor:
  • Committer: the submitter

2.3 Submission Information

Displays specific information about commits or diFF differences between two commits.

2.3.1 Option Parameters

  • Diff: Displays two submissionsdiffdifferences
  • Old version: the old version
  • New versionNew version:
  • Lines of context: Changes the number of context lines in the region
  • ignore space change: Ignores space changes
  • diffStyles: includingLine diff,Markup wordsandColor words

2.3.2 Submitting information

  • AuthorAuthor:
  • Committer: the submitter
  • Tags: Indicates the current label node
  • Parent: Parent commit of the current commit, merge commit has multiple parent commits
  • Branches: Indicates the nearest branch of the current node
  • Follows: Indicates the last label of the current node
  • Precedes: Indicates the next label of the current node

Version 2.4 of the tree

2.4.1 Option Parameters

  • Patch: Displays only the list of changed files
  • Tree: Displays the complete file tree

2.4.2 Right-click the menu

  • Highlight this too: Highlights the submission record of this file that has been modified
  • Highlight this only: Only the submission record of this file is highlighted. If other files are highlighted in the current submission history, unhighlight the other files
  • External diff: Use externaldiffTool to view
  • Blame parent commit: View the change record of the entire contents of this file
  • Copy path: indicates the path to copy files

3 Git Gui

Git Gui is also a built-in visualization tool for Git. Most operations are much more convenient than the command line, and some temporary storage is not available in the command line.

Right click Git GUI Here in the root directory of the repository or run Git GUI from the command line to open the following visual interface. It mainly includes five areas: menu bar A, Workspace change B, difference comparison C, temporary storage AREA D, and submission information E.

3.1 the menu bar

3.1.1 the Repository

  • Explore Working Copy: Browse the working directory
  • Git Bash:GitThe command line
  • Browse master's Files: Browse the current branch file
  • Browse Branch Files: Browse all branch files, whereRevision ExpressionIs a version regular expression, and the available branches include local branchesLocal Branch, remote tracking branchTracking Branch, labels,Tag, search bar keyword to search for the selected branch

  • Visualize master's History: Visualize the history of the current branch
  • Visualize All Branch History: Visualize the history of all branches
  • Database Statistics: Database statistics, including the number of loose objectsNumber of loose objects, disk space occupied by loose objectsDisk space used by loose objects, the number of objects in the package fileNumber of packed objects, number of package filesNumber of packs, disk space occupied by objects in package filesDisk space used by packed objectsLoose objects in package filesPacked objects waiting for pruningGarbage filesGarbage files.Compress DatabaseThe packaginggit gcThe database

  • Compress DatabasePackage database
  • Verify DatabaseValidation:fsckDatabase consistency and validity
  • Create Desktop Icon: Creates a desktop icon
  • Quit: quit

3.1.2 Edit

Edit is used to manipulate the submission information area, including Undo, Redo, Cut, Copy, Paste, Delete Delete, Select All, and Options.

Repo Repository is the configuration option of the current Repository, and Global (All Repository) is the configuration option of the Global Repository.

  • Summarize Merge Commits: summarize merge commits
  • Show Diffstat After Merge: Is displayed after the mergediffstatistical
  • use Merge Tool: Use the merge tool
  • Trust File Modification Timestamps: Change time of the trust file
  • Prune Tracking Branches During Fetch: Clears trace branches when fetching
  • Match Tracking Branches: matching trace branch
  • Use Textconv For Diffs and Blames: Use for discrepancies and annotationsTextconv
  • Blame Copy Only On Changed Files: Files marked with changes only
  • Maximum Length of Recent Repositories List: Indicates the maximum length of the current version library list
  • Minimum Letters To Blame Copy On: Minimum number of letters to annotate the copy
  • Blame History Context Radius (days): Annotate historical context range (days)
  • Number of Diff Context Line:diffThe number of context lines that differ
  • Additional Diff Parameters: otherdiffparameter
  • Commit Message Text Width: Width of the text of the submission message
  • Commit Message Text Width: New branch name template
  • Default File Contents Encoding: Indicates the default file content encoding format
  • Warn before committing to a detached head: Submit to a dissociatedHEADBefore the warning
  • Staging of untracked files: Temporarily stores untraced files, including yesyes, nonoOr askask
  • Show untracked files: Displays untraced files

3.1.3 Branch

  • Create: Creates a branch. Enter a branch nameNameCreate, or match remote trace branchesMatch Tracking Branch NameCheck out the trace branch. Or branch from the localLocal Branch, remote tracking branchTracking Branch, labels,TagCheck out the branch, associated branch optionsOptionsBranches that exist for updatesUpdate Existing Branch, including no operationNo, just fast forwardFast Forward OnlyReset,Reset, pull trace branchFetch Tracking BranchAfter the branch is created and checked outCheckout After Creation

  • Checkout: Checks out branches
  • Rename: Renames the branch
  • Delete: Delete branch
  • Reset: resets the current branch, which will be lost if any uncommitted changes are included

3.1.4 Commit

  • Amend Last Commit: Modifies the last commit
  • Rescan: refresh, external command line operation version library, refresh synchronization
  • Statge To Commit: Temporarily saves the selected file
  • Stage Changed Files To Commit: Temporarily saves workspace files
  • Unstage Form Commit: Unsaves the temporarily selected file
  • Show Less Context:diffShow less context
  • Show More Context:diffDisplay more context
  • Sign Off: Operator information is added at the end of the submission information. Generally, it is not clear about the source of the submission record when selecting, so operator information can be added to facilitate traceability
  • CommitSubmitted:

3.1.5 the Merge

  • Local Merge: Select local branch merge
  • Abort Merge: Undoes a merge, in some cases causing a conflict, and returns to the state before the merge

3.1.6 Remote

  • Fetch from: Gets a remote library update
  • Prune from: Clipping trace branches removed from a remote library
  • Remove Remote: Deletes a remote library
  • Add: Adds a remote library, including immediate pullFetch ImmediatelyInitialize and push the remote repositoryInitialize Remote Repository and PushAnd no actionDo Nothing EIse Now

  • Push: Push, which can be pushed to a specified remote repository or forcibly overwrite existing branchesForce overwrite existing branch (may discard changes), use simple packageUse thin pack (for slow network connections), including local labelsInclude tags

  • Delete Branch: Deletes a branch of a remote library

3.1.7 Tools

  • Add: Adds a new command, including the command nameName, command instructionCommand, can display the dialog box before runningShow a dialog before running, the user selects a versionAsk the user to select a revisionOr ask the user for additional parametersAsk the user for additional argumentsThe command output window is not displayedDon't show the command output window, only selecteddiffJust runRun only if a diff is selected

  • Remove: Deletes an added command

3.1.8 Help

  • About Git Gui: aboutGit Gui
  • Online Documentation: Online documents
  • Show SSH Key: displaySSHPublic key, currently not available to clickGenerate KeygenerateKey

3.2 Comparison of Differences

Difference contrast area without any files when right-click menu.

  • Undo Last Revert: Revokes the last discardRevert, discard filesRevert HunkOr discardedRevert LineAll changes are discarded,Git BashThe command linegit checkoutChanges that are discarded cannot be recovered, butGit GuiCaches the version of the file before the last discarding
  • RefreshRefresh:
  • CopyCopy:
  • Select All: all
  • Copy All: Copy all
  • Decrease Font Size: Reduce font size
  • Increase Font Size: Enlarge font
  • Encoding: File content encoding
  • OptionsOptions:

3.3 Workspace Change

Click the blue icon in front of the file to quickly save the file, contrast the difference to open part of the right menu.

  • Stage Hunk For Commit: Temporary file
  • Stage Line For Commit: Temporarily saves a row or more rows, which can be selected by clicking a row or selecting multiple rows
  • Rever Hunk: Undoes or discards changes to a file
  • Rever Line: Undoes or discards the modification of one or more lines
  • Show Less Context: Displays less context
  • Show More Context: Displays more context

3.4 the staging area

Click the green icon before the file to quickly cancel the temporary file, contrast the difference to open part of the right menu.

  • Unstaged Hunk From Commit: Cancels the temporary file
  • Unstaged Line From Commit: Cancels one or more lines of the temporary file

3.5 Submitting Information

  • RescanRefresh:
  • Staged Changed: Temporary file
  • Sign Off: Sign, add operator information to the end of the submission information
  • Push: push
  • Amend Last Commit: Modifies the last commit
  • Commit Message: Submit information

Submit information right-click menu and menu bar basically the same.

In the previous