Git Command Complete

Posted by sane993 on Sun, 19 Sep 2021 01:10:32 +0200

Git Command Complete
git config
Configure Git's parameters.

Git has three profiles:

  1. Warehouse-level configuration file: At the warehouse's.git/.gitconfig, the configuration file is valid only for the warehouse in which it resides.
  2. Global profile: Mac system at ~/.gitconfig, Windows system at C:\Users<User name>.gitconfig.
  3. System-level configuration files: gitconfig in the etc folder of the Git installation directory (Mac installation directory in/usr/local/git).

View configuration information

- local: warehouse level, - global: global level, - system: system level

$ git config <--local | --global | --system> -l

View the configuration information currently in effect

$ git config -l

Edit Profile

- local: warehouse level, - global: global level, - system: system level

$ git config <--local | --global | --system> -e

Add Configuration Item

- local: warehouse level, - global: global level, - system: system level

$ git config <--local | --global | --system> --add <name> <value>

Get Configuration Items

$ git config <--local | --global | --system> --get <name>

Delete Configuration Items

$ git config <--local | --global | --system> --unset <name>

Configure user information in submission records

$ git config --global user.name <User name>
$ git config --global user.email <E-mail address>

Change the size of the Git cache

If the submission is large and the default cache is small, the submission will fail

Cache size unit: B, for example: 524288000 (500MB)

$ git config --global http.postBuffer <Cache size>

Show change status in highlight or color when git status/git diff command is called

$ git config --global color.ui true

Configure to cache passwords, default cache time 15 minutes

$ git config --global credential.helper cache

Configure the cache time for passwords

Cache time unit: seconds

$ git config --global credential.helper 'cache --timeout=<Cache time>'

Configure Long-term Storage Password

$ git config --global credential.helper store

git clone

Clone a version library from a remote repository to a local repository.

By default, a folder with the same version library name is created in the current directory and downloaded to it

$ git clone <Web address of remote warehouse>

Specify directories for local warehouses

$ git clone <Web address of remote warehouse> <Local directory>

-b Specifies the branch to clone, default is master branch

$ git clone <Web address of remote warehouse> -b <Branch name> <Local directory>

git init

Initialize the directory where the project is located, and a directory named.git will appear in the current directory after initialization.

Initialize the local repository to generate the.git folder in the current directory

$ git init

git status

View the status of the local warehouse.

View the status of the local warehouse

$ git status

View the status of the local warehouse in short mode

Two columns are displayed, the first is the status of the file and the second is the corresponding file

File Status: A New, M Modified, D Deleted,??Not added to Git

$ git status -s

git remote

Operate remote libraries.

List existing remote warehouses

$ git remote

List the details of the remote warehouse and the URL address after the alias

$ git remote -v
$ git remote --verbose

Add Remote Warehouse

$ git remote add <Alias of remote warehouse> <Remote warehouse URL address>

Modify the alias of the remote warehouse

$ git remote rename <Alias of original remote warehouse> <New Alias>

Delete remote warehouse with specified name

$ git remote remove <Alias of remote warehouse>

Modify URL address of remote warehouse

$ git remote set-url <Alias of remote warehouse> <New remote warehouse URL address>

git branch

Branch commands that operate on Git.

List all local branches, the current branch is marked with'*'

$ git branch

Lists all local branches and shows the last submission. The current branch is marked with'*'

$ git branch -v

Create a new branch based on the last submission

$ git branch <Branch name>

Modify Branch Name

Current branch if the original branch name is not specified

$ git branch -m [<Original Branch Name>] <New Branch Name>

Force Branch Name Modification

$ git branch -M [<Original Branch Name>] <New Branch Name>

Delete the specified local branch

$ git branch -d <Branch name>

Force deletion of specified local branch

$ git branch -D <Branch name>

git checkout

Check out commands for creating, switching branches, and so on.

Switch to an existing specified branch

$ git checkout <Branch name>

Create and switch to the specified branch, keeping all submission records

Merge of two commands equal to "git branch" and "git checkout"

$ git checkout -b <Branch name>

Create and switch to the specified branch, delete all submission records

$ git checkout --orphan <Branch name>

Replace local changes, new files and content added to the staging area will not be affected

$ git checkout <File Path>

git cherry-pick

Merge the submitted records into the current branch.

Merge submitted records into the current branch

$ git cherry-pick <commit ID>

git add

Add information about the file to be submitted to the staging area. When git commit is used, file submissions will be based on what is in the staging area.

Adds the specified file to the staging area

$ git add <File Path>

Add all modified, deleted files to the staging area

$ git add -u [<File Path>]
$ git add --update [<File Path>]

Add all modified, deleted, and added files to the staging area, omitting File Path is the current directory

$ git add -A [<File Path>]
$ git add --all [<File Path>]

View all modified, deleted, but uncommitted files and enter a subcommand system

$ git add -i [<File Path>]
$ git add --interactive [<File Path>]

git commit

Submit the files in the staging area to the local warehouse.

Submit the file in the staging area to the local repository and call the text editor to enter the description of the submission

$ git commit

Submit the files in the staging area to the local repository and add descriptive information

$ git commit -m "<Descriptive information submitted>"

Submit all modified, deleted files to the local repository

Does not include files that are not tracked by the version library, equivalent to calling "git add-u" first

$ git commit -a -m "<Descriptive information submitted>"

Modify last submitted description information

$ git commit --amend

git fetch

Get the latest version from the remote repository to the local tmp branch.

Retrieve the latest version of all branches of the remote warehouse back locally

$ git fetch <Alias of remote warehouse>

Retrieve the latest version of the specified branch of the remote warehouse back locally

$ git fetch <Remote Host Name> <Branch name>

git merge

Merge branches.

Merge the specified branch under the current branch

$ git merge <Branch name>

git diff

Compare differences between versions.

Compare the differences between the current file and the files in the staging area to show that no changes have been temporarily saved

$ git diff

# Compare the differences between files in the staging area and the last submission
$ git diff --cached
$ git diff --staged

Compare the differences between the current file and the last submission

$ git diff HEAD

View changes since the specified version

$ git diff <commit ID>

Compare the differences between the two branches

$ git diff <Branch name> <Branch name>

View the changes made when the two branches are separated

$ git diff <Branch name>...<Branch name>

git pull

Get the latest version from the remote repository and merge it locally.
First the git fetch is executed, then the git merge is executed, merging the obtained branch's HEAD into the current branch.

Get the latest version from the remote repository.

$ git pull

git push

Push submissions from local warehouses to remote warehouses.

Push branch of local warehouse to specified branch of remote warehouse

$ git push <Alias of remote warehouse> <Local Branch Name>:<Remote Branch Name>

Delete branch of specified remote warehouse

$ git push <Alias of remote warehouse> :<Remote Branch Name>
$ git push <Alias of remote warehouse> --delete <Remote Branch Name>

git log

Display submitted records.

Print all submission records

$ git log

# Print records from first submission to specified submission
$ git log <commit ID>

Print a specified number of recently submitted records

$ git log -<Quantity specified>

git reset

Restore the submission record.

Reset the staging area, but the file is not affected

Equivalent to evacuating content that is updated to the staging area using the "git add" command, you can specify a file

Default to current HEAD if commit ID is not specified

$ git reset [<File Path>]
$ git reset --mixed [<File Path>]

Change direction of HEAD, undo to specified submission record, file not modified

$ git reset <commit ID>
$ git reset --mixed <commit ID>

Change direction of HEAD, undo to specified submission record, file not modified

It's equivalent to calling the "git reset --mixed" command and then doing a "git add"

$ git reset --soft <commit ID>

Changes the direction of HEAD, undoes the specified submission record, and changes the file

$ git reset --hard <commit ID>

git revert

Generate a new submission to revoke a submission, and all submissions prior to this submission will be retained.

Generate a new submission to undo a submission

$ git revert <commit ID>

git tag

Command to manipulate labels.

Print all labels

$ git tag

Add a lightweight tag pointing to a reference to the submission object to specify the previous submission record

$ git tag <Label Name> [<commit ID>]

Add a note label with descriptive information to specify previous submission records

$ git tag -a <Label Name> -m <Label Description Information> [<commit ID>]

Switch to the specified label

$ git checkout <Label Name>

View label information

$ git show <Label Name>

Delete the specified label

$ git tag -d <Label Name>

Submit the specified label to the remote warehouse

$ git push <Alias of remote warehouse> <Label Name>

Submit all local labels to remote warehouse

$ git push <Alias of remote warehouse> –tags

git mv

Rename a file or folder.

Rename the specified file or folder

$ git mv <source file/Folder> <Target File/Folder>

git rm

Delete files or folders.

Remove trace specified files and delete them from folders in the local repository

$ git rm <File Path>

Remove the folder specified by the trace and delete it from the folder in the local repository

$ git rm -r <Folder Path>

Remove the file specified by the trace and keep it in folders in the local repository

$ git rm --cached

Example Git action scenario

  1. Remove remote branches that do not exist locally
    If a remote branch is deleted by another development when multiple people work together, executing git branch locally --all will still show the remote branch and can be deleted using the following commands:

Using the pull command, add the -p parameter

$ git pull -p

Equivalent to the following command

$ git fetch -p
$ git fetch --prune origin

Topics: git