Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

configuration

Viewing All Configurations

git config --list

View all configurations and the files they are in

git config --list --show-origin

Setting User Information

git config --global user.name "John Doe"

git config --global user.email [email protected]

If you use the –global option, then this command only needs to be run once, because Git uses that information later on, whenever you do anything on the system. When you want to use a different user name and email address for a particular project, you can configure it by running a command in that project directory without the –global option.

Viewing Configuration Information

git config <key>

For example, check the user name git config user.name

help

The following three approaches are equivalent

git help <verb> git <verb> --help man git-<verb>

Suppose I want to check the config help documentation

Git config –help or git config -h

basis

Obtaining Git repository

Clone an existing warehouse

git clone <url>

Git clone -b

Record each update to the warehouse

Check current file status < workspace, staging >

Git status: See which files are in what state

Git status -s

Ignore files

Create a.gitignore file in the directory and write the files to be ignored

The format of the.gitignore file is as follows: All empty lines or lines starting with # are ignored by Git. Standard Glob pattern matching can be used, which is applied recursively throughout the workspace. Matching patterns can prevent recursion by starting with a (/). A matching pattern can end with a/to specify a directory. To ignore files or directories outside the specified schema, precede the schema with an exclamation point (!). The notCopy the code

example

# ignore all.a files *. A # but keep track of all lib.a, even if you ignored.a files earlier! Lib. A # ignore only TODO files in the current directory, not subdir/TODO /TODO # ignore any folder named build under the directory build/ # ignore doc/notes. Doc /server/arch.txt doc/*.txt # Ignore.pdf files in doc/ and all subdirectoriesCopy the code

GitHub has a very detailed list of.gitignore files for dozens of projects and languages, which you can find at github.com/github/giti… Find it.

contrast

git diff

To see what parts of a file that have not yet been provisionally updated, type git diff without arguments:

To see what has been staged and will be added to your next commit, use git diff –staged commands. This command compares the difference between the provisioned file and the last submitted file:

Use Git diff –cached to view changes that have been temporarily stored

submit

git commit

Git commit -am

Modifying Submission Information

git commit --amend

Remove the file

Git rm: will be deleted from both the staging and working directories

Git rm –cached

: it is only removed from the staging area. It remains in the current directory and will not be traced

Git rm can be used to list the names of files or directories

$git rm log/\*. Log $git rm \*~ # This command will delete all files whose names end with ~.Copy the code

Move files

git mv file_from file_to

View submission History

View submission History

Git log: Lists the SHA-1 checksum for each submission, the author’s name and E-mail address, the submission time, and the submission instructions.

By default, without passing in any arguments, git log lists all commits in chronological order, with the most recent update at the top.

One of the more useful options is -p or –patch, which displays the differences introduced with each commit (in the format of the patch). You can also limit the number of log entries displayed, for example using the -2 option to show only the last two commits:

git log -p -2

If you want to see the summary statistics for each submission, you can use it--statOptions:

git log --stat

Formatted display

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

options instructions
%H The full hash value of the submission
%h The shorthand hash value of the submission
%T The full hash of the tree
%t Short for tree hash value
%P The full hash value submitted by the parent
%p The shorthand hash value submitted by the parent
%an Author’s name
%ae Email address of the author
%ad Author revision date (can be customized with the –date= option)
%ar Author revision date, in the manner of how long ago
%cn Name of the submitter
%ce Email address of the submitter
%cd Submission date
%cr Date of submission (how long ago)
%s Submit instructions
options instructions
-p Shows the differences introduced by each commit in patch format.
--stat Displays file modification statistics for each submission.
--shortstat Show only the last row number modification in –stat add remove statistics.
--name-only A list of modified files is displayed only after the information has been submitted.
--name-status Displays the list of new, modified, and deleted files.
--abbrev-commit Only the first few characters of all 40 characters in the SHA-1 checksum are displayed.
--relative-date Display dates in short relative times instead of full formats (such as “2 weeks ago”).
--graph Displays branch and merge history in ASCII graphics next to the log.
--pretty Display historical submission information in another format. The options available include oneline, short, Full, Fuller, and Format (to define your own format).
--oneline --pretty=oneline --abbrev-commitShort for shared.

Cancel the operation

Sometimes we submit only to find that several files have not been added or the submission information has been incorrectly written. At this point, you can resubmit by running the commit command with the –amend option:

git commit --amend

Cancel the temporary file

git reset HEAD CONTRIBUTING.md

Undo changes to a file

git checkout -- CONTRIBUTING.md

Use of remote warehouses

As a developer, how do I view remote warehouses?

Git Remote: Short for viewing remote repository servers

Git remote -v: displays the shorthand and URL of the Git save that needs to be read and written to the remote repository

As a developer, I wanted to add a remote repository

git remote add <shortname> <url>

As a developer, I want to pull my remote warehouse

git fetch <remote-name>

I want to push it to the remote warehouse

git push origin master

I’d like to see more information about a remote warehouse

git remote show origin

As a developer, I would like to rename or remove my remote repository

git remote rename <shortname> <shortnewname> # rename
git remote remove <shortname> # remove
Copy the code

tagging

As a developer, I want to see how many tags I have under my current project

git tag

As a developer, I wanted to find tags associated with 1.8.5

Git tag - l "v1.8.5 *"

As a developer, I want to create a tag

GIt supports two types of tags: Lightweight and Annotated.

A lightweight tag is much like a branch that doesn’t change — it’s just a reference to a particular submission.

An annotation tag is a complete object stored in a Git database that can be verified and contains the tag tag’s name, email address, date and time, in addition to a tag information that can be signed and verified using the GNU Privacy Guard (GPG). It is often recommended to create a footnote tag so that you have all of the above information. But if you just want to use a temporary tag, or for some reason don’t want to keep the information, then you can also use lightweight tags.

Git tag -a v1.4-m “My versuib 1.4” : create an annotation tag

Git tag v1.4-1w: Create a lightweight tag

Git show v1.4: Check the committed information

As a developer, I want to label past submissions

Git tag-a v1.29fceeb02

As a developer, I want to remove a tag

Git tag -d v1.4-1w: Deletes the local tag

Git push Origin :refs/tags/v1.4-1w: Remove remote tags

or

git push origin --delete <tagname>

As a developer, I want to check out a tag

Git checkout -b version2 v2.0.0

Git alias

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
Copy the code

Get your own

git config --global alias.unstage 'reset HEAD --'
# This makes the following two commands equivalent:
$ git unstage fileA
$ git reset HEAD -- fileA 
Copy the code

Branching model: Killer feature

start

HEAD special pointer: In Git, this is a pointer to the current local branch

As a developer, I wanted to create a test branch

git branch test

As a developer, I want to switch to my new Test branch

git checkout test

As a developer, I want to create and switch to a new branch

git checkout -b new-branch

# Explanation: The above code is a shorthand for the following two names
git branch new-branch
git checkout new-branch
Copy the code

Merging branches

git checkout master
git merge hotfix
> Fast-forward
Delete the hotfix branch
git checkout -d hotfix
Copy the code
Resolve the conflict

Why the conflict?

If you make different changes to the same part of the same file in two different branches, Git can’t merge them cleanly. If your changes to the #53 problem and the changes to the Hotfix branch both involve the same part of the same file, merging them will cause merge conflicts

First, use git status to view files that are in the merged state due to inclusion conflicts

Then use the editor to modify, then add, commit

Branch management

As a developer, I want to see a list of branches of my project

git branch

As a developer, I want to see the last commit of each branch

git branch -v

As a developer, I want to see which branches have been merged into the current branch

git branch --merged

As a developer, I want to see which branches are merged into the current branch

git branch --no-merged

As a developer, I want to delete the merged branches

git branch --merged
testing
git branch -d testing
Copy the code

Branch development workflow

Long term branch Subject branch (short term branch)

Remote branch

As a developer, I want to explicitly get the completion list of remote references

git ls-remote

As a developer, I want to push content to a remote branch

`git push origin master

As a developer, I want to create a theme branch based on the remote Master branch and switch to that branch

git checkout master
git pull origin master
git push origin HEAD:<branchname>
git checkout -b <branchname> <branchname/branchname>
Copy the code

rebase

There are two main ways to integrate changes from different branches in Git: Merge and Rebase.

You can use the rebase command to move all changes committed to one branch to another

git checkout experiment
git rebase master
Copy the code

The problem

Git pull origin git pull origin/master Git pull Origin Master is a git merge origin master.Copy the code