Home > Development Tools > git > body text

Introducing the list of commonly used Git commands

coldplay.xixi
Release: 2021-04-14 19:49:15
forward
2813 people have browsed it

Introducing the list of commonly used Git commands

1. Quick check of common Git commands

git branch View all local branches
git status View the current status
git commit Submit
git branch -a View all branches
git branch -r View all remote branches
git commit -am "init" Submit and add comments
git remote add origin git@192.168.1.119:ndshow
git push origin master Push the file to the server
git remote show origin Display the resources in the remote library origin
git push origin master:develop
git push origin master:hb-dev Compare the local library to the server Library association
git checkout --track origin/dev Switch to the remote dev branch
git branch -D master develop Delete the local library develop
git checkout -b dev Create a new local branch dev
git merge origin/dev Merge branch dev with the current branch
git checkout dev Switch to the local dev branch
git remote show View the remote library
git add .
git rm file name (including path) Delete the specified file from git
git clone git://github.com/schacon/grit.git Pull the code from the server
git config --list View all users
git ls-files View what has been submitted
git rm [file name] Delete a file
git commit -a Commit all changes to the current repos
git add [file name] Add a file to git index
git commit -v When you use the -v parameter, you can see the difference in commits
git commit -m "This is the message describing the commit" Add commit information
git commit -a -a represents add, adding all Add the change to the git index and then commit
git commit -a -v General commit command
git log Look at your commit log
git diff Check the updates that have not been staged
git rm a.a move Remove files (delete from the staging area and workspace)
git rm --cached a.a Remove files (only delete from the staging area)
git commit -m "remove" Remove files (from Git Delete)
git rm -f a.a forcefully remove the modified file (delete from the staging area and workspace)
git diff --cached or $ git diff --staged to view uncommitted updates
git stash push Push the file to a temporary space
git stash pop Pop the file from the temporary space
--------------------- ------------------------------------
git remote add origin git@github.com:username /Hello-World.git
git push origin master Submit the local project to the server
-------------------------- ----------------------------------
git pull local and server synchronization
---- -------------------------------------------------- -----------
git push (remote warehouse name) (branch name) Push the local branch to the server.
git push origin serverfix:awesomebranch
----------------------------------------- ----------------------------
git fetch is equivalent to getting the latest version from the remote to the local, and will not automatically merge
git commit -a -m "log_message" (-a is to submit all changes, -m is to add log information) Local changes are synchronized to the server:
git branch branch_0.1 master creates branch_0.1 branch from the main branch master
git branch -m branch_0.1 branch_1.0 Rename branch_0.1 to branch_1.0
git checkout branch_1.0/master Switch to branch_1.0/master branch
du -hs

git branch delete remote branch
git push origin :branch_remote_name
git branch -r -d branch_remote_name
---------------------- -------------------------------------

Initialize the version library and submit it to Remote server side
mkdir WebApp
cd WebApp
git init local initialization
touch README
git add README add file
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git

Add a remote server

The above command will add a remote server library with the URL address 'git@github.com:daixu/WebApp.git' and the name origin. When submitting code in the future, you only need to use the origin alias

Recommendation (free): Git

2. Git command cheat sheet

1. Commonly used Git commands


##Apply patchgit am##Binary searchgit blameFile traceback line by linegit branchBranch Managementgit cat-fileRepository Object Research Toolgit checkoutCheckout to workspace, switch or create branch##Clear untracked files in the workspacegit clonegit commitgit configgit describe##help##Display commit loggit mergeBranch mergegit mergetoolGraphical conflict resolutiongit mvRenamegit pullPull back the commit of the remote repository##Interactive branch rebasegit refloggit remotegit repo-config*git resetcursor" points to ## Synonyms, equivalent to git addgit stashSaving and restoring progressgit statusDisplay workspace file status


2. Commands related to object library operations


Command

Brief description

##git add

Add to the staging area

git add–interactive

Interactive add

##git apply

##Apply email format patch

git annotate

## Synonyms, equivalent to git blame

git archive

##File archive packaging

git bisect

git cherry-pick

##Submit pick

git citool

##Graphical submission, equivalent to git gui

Command

git clean

##Clone repository

##submit

Query and modify configuration

Visually display commit IDs by milestone

git diff

##Difference comparison

git difftool

Calling the graphical difference comparison tool

git fetch

Get the commit of the remote repository

git format-patch

Create a patch file in email format. See git am Command

##git grep

file content Search positioning tool

git gui

Based on Tcl/ Tk

's graphical tool, focusing on operations such as submission

git help

git init

##Repository initialization

git init-db*

## Synonyms, equivalent to git init

git log

git push

##Push to the remote repository

git rebase

##branch rebase

git rebase–interactive

## Branch and other reference change record management

Remote repository management

Synonyms, equivalent to git config

Reset changed branch "

git rev-parse

Convert various reference representations to hashes Value etc

git revert

Reverse commit

##git rm

Delete file

git show

##Display various types of objects

git stage*

git tag

##Milestone Management

Commands

A brief description

git commit-tree

Creates a commit from a tree object

# #git hash-object

Compute hash value or create object from standard input or file

git ls-files

Display workspace and staging area files

git ls-tree

Display the files contained in the tree object

git mktag

Read standard input to create a milestone object

git mktree

Read standard input to create a tree object

git read-tree

Read the tree object to the temporary storage area

git update-index

Register the workspace content to the staging area and manage the staging area

git unpack-file

Creates a temporary file containing the contents of the specified blob

git write-tree

Create a tree object from the staging area


3. Reference operation related commands


##git show-ref Show local ref##git symbolic-ref##git update-ref git verify-tag

Command

Brief description

##git check-ref-format

Check whether the reference name conforms to the specification

##git for-each-ref

Reference iterator, for shell

Programming

git ls-remote

Display references to remote repositories

git name-rev

Display commit ID

as friendly name

git peek-remote*

Outdated commands, please use git ls-remote

##git rev-list

Show version range

##git show-branch

Display branch list and topological relationship

Display or set symbol references

Update reference point

Verify GPG

Signed Tag


4. Commands related to repository management


##git pack-refsPack references into .git/packed-refs git pruneDelete expired objects from the object library##git prune-packed


5. Data transmission related commands


command

A brief description

git count-objects

Displays the number of loose objects and disk usage

git filter-branch

Repository reconstruction

git fsck

Object library integrity check

##git fsck-objects*

Synonyms, equivalent to git fsck

git gc

Repository storage optimization

git index-pack

##Create the corresponding index file from the package file

##git lost-found*

Outdated, please use git fsck –lost-found

Command

git pack-objects

Read the object ID

from the standard input and pack it into the file

git pack-redundant

Find redundant pack

files

files

#Delete the packed loose objects

git relink

##Establish a hard link to the same object in the local repository

##git repack

Loosely unpack the repository Object packaging

git show-index

read The index file of the package, showing the contents of the package file

git unpack-objects

Release files from pack file

git verify-pack

Verify object library package file

#


6. Email related commands


Command

A brief description


git fetch-pack

Execute this command locally when executing the git fetch or git pull command, used to download from Other repositories get missing objects

git receive-pack

A command executed remotely when executing the git push command, used to accept pushed data

git send-pack

The command executed locally when executing the git push command is used to push data to other repositories

git upload-archive

Execute git archive –remote When the command creates an archive based on the remote repository, the remote repository executes this Command transfer archive

git upload-pack

##Execute git fetch or git pull command Execute this command remotely to package and upload the object

##git mailinfoExport commit instructions and patches from mail## git mailsplit or Maildir format mailbox one by one into filesgit request-pull operationgit send-email

##Command

Brief description

##git imap -send

Send the patch via IMAP

Extract the emails in the mbox

Create a message containing the differences between commits and the address to perform the PULL

send email


7. Protocol related commands


##git http-backendCGI program that implements HTTPgit instawebInstantly launch the browser through gitweb git shellRestricted shellgit update-server-info##git remote-fdInvoked by the Gitgit remote-ftpCalled by the Gitgit remote-ftps is called by the Gitgit remote-http

##Command

Brief description

##git daemon

Implement Git

protocol

protocol and supports intelligent HTTP protocol

Browse the current version library

, provides SSH access to execute only Git commands

Update the auxiliary files required for the dumb protocol

##git http-fetch

Get the repository through HTTP protocol

##git http-push

Push via HTTP/DAV

protocol

git remote- ext

is called by the Git

command and provides extended protocol support through external commands

command, using the file descriptor as the protocol interface

command to provide support for the FTP protocol

command, Provide support for FTPS protocol

Called by the Git command, providing support for the HTTP protocol

git remote- https

is called by the Git command and provides support for the HTTPS protocol

git remote-testgit

Protocol extension example script


8. Commands related to repository conversion and interaction



9. Merge related auxiliary commands


Command

Brief description

##git archimport

Import Arch repository to Git

git bundle

Submit packaging and unpacking for transfer between different repositories

git cvsexportcommit

Check out a Git commit as a CVS

git cvsimport

Import the CVS repository to Git. Or use cvs2git

git cvsserver

Git's CVS protocol simulator allows CVS commands to access the Git repository

git fast-export

Export commits to git-fast-import Format

git fast-import

Common tool for migrating other repositories to Git

git svn

##Git As a front-end operation Subversion


10. Miscellaneous


command

A brief description

git merge-base

can be called by other scripts to find the nearest common ancestor of two or more commits

git merge-file

Perform a three-way file merge against two different versions of a file

git merge-index

##Conflicts in index File calls the specified conflict resolution tool

git merge-octopus

Merge two or more branches. See git merge ’s octopus merge strategy

git merge-one-file

Standard helper program called by git merge-index

git merge-ours

# Merge and use the local version and discard other people’s versions. See ours merge strategy for git merge

git merge-recursive

For three-way merge of two branches. See the recursive merge strategy of git merge

git merge-resolve

For three-way merge of two branches. See the resolve merge strategy of git merge

git merge-subtree

Subtree merge. See the subtree merge strategy of git merge

git merge-tree

Explicit three-way merge results, do not change the staging area

##git fmt-merge-msg

Called by scripts that perform merge operations and used to create a merge commit description

git rerere

##Reuse documented conflict resolution

##git check-attrDisplay whether a file has a certain attribute setgit checkout-indexCopy files from the staging area to the work areagit cherryFind commits that have not been merged into upstreamgit diff-files##git patch-id##git submoduleSubmodule management ##git tar-treegit var##git-mergetool –lib Included among other scripts, provides selection and execution of merge/git-parse-remoteContained in other scripts, providing functions for operating remote repositories##git-sh-setupProgramming function library

##Command

Brief description

##git bisect–helper

Called by the git bisect

command to confirm the binary search progress

Compare the staging area and the work area, equivalent to git diff –raw

git diff-index

Compares the staging area and the repository, equivalent to git diff –cached –raw

git diff-tree

Compares two tree objects, equivalent to git diff –raw A B

git difftool–helper

command by git difftool Called, the default diff comparison tool to be used

##git get-tar-commit-id

Extract the commit ID from the tar package created by git archive

##git gui–askpass

Command git gui

Get user password input interface

git notes

Submit comment management

The patch generates a unique ID after filtering line numbers and whitespace characters

##git quiltimport

Apply the Quilt patch list to the current branch

git replace

Commit replacement

##git shortlog

Summary output of git log

, suitable for product release instructions

git stripspace

Remove empty lines for other scripts to call

Outdated command, please use git archive

Show Git Environment variables

##git web–browse

Launch a browser to view a directory or file

##git whatchanged

Display submission history and changes for each submission

diff comparison tools

is included in other scripts, provided shell


The editor of Script House below will share with you a picture version of the

Git common command quick check list. Click for larger image.

Git Command Reference Manual (text version)

Git Init#Initialized the local Git warehouse (created a new warehouse)
Git Config -Global User.name "xxx"#Configure user name
git config --global user.email "xxx@xxx.com "              #Configuration email
git config --global color.ui true                                                                                                                                                                                                                                                                 since git config --global color.branch auto
git config --global color.interactive auto
git clone git ssh://git@192.168.53.168/VT.git #clone remote warehouse
git status       # Check the current version status (whether modified)
git add xyz                                                                                                            # Add all changed files in the current subdirectory to index
git commit -m 'xxx'                                                                                             Submit
Git Commit -ADEEND -M 'XXX'#merged last submit (for repeated modification)
Git Commit -AM 'XXX'#to combine ADD and Commit into one step
git rm xxx# Delete files in index
git rm -r *                                                                                                                                                                                                          Display commit log
git log -1                                                                                                                                                                                                                            ##git log --statgit log -p -m
git show dfb02e6e4f2f7b573337763e5c0013802e392818                                                                                   # You can only use the first few digits of commitid
git show HEAD                                                                                                                                                   show HEAD^                                                                                                                                                                            ​​​​ #Show existing tags
git tag -a v2. 0 -m 'xxx'#Add V2.0's tag
Git Show v2.0#Display v2.0 log and detailed content
git log v2.0#Display v2.0 log
git differ #git diff HEAD^                                                                                                                                                                                                 because HEAD -- ./lib                                                                                                                                                                                                                                      --stat                                                                                                                                                                                                                                 ​​​​​git branchgit Branch -a#Show all branches
Git Branch -R#display all original branches
Git Branch -Merged#Show all branches that have been merged to the current branch
Git Braanch --no -Merged#display All branches that have not been merged into the current branch
git branch -m master master_copy #Rename the local branch
git checkout -b master_copy #Create a new branch master_copy from the current branch and check out
git checkout -b master master_copy                  # The full version of the above
git checkout features/performance # Check out the existing features/performance branch
git checkout --track hotfixes/BJVEP933 # Check out the remote branch hotfixes/BJVEP933 and create a local tracking branch
git checkout v2.0                                                                                                                                                                                                                                                                                                    because​​​​​​​​​​ File (can be used to modify error rollback)
git merge origin/master                                                                                                                                                                                                                                                        Modifications of 8e
git push origin master Push to the remote master branch
git push origin :hotfixes/BJVEP933 #Delete the hotfixes/BJVEP933 branch of the remote repository
git push --tags #Push all tags to the remote repository
git fetch                                                                                                              (The local branch will not be updated, and another merge is required)
git fetch -propune#Get all original branches and remove the branches that have been deleted on the server
Git Pull Origin Master#Get the remote branch Master and Merge to the current branch
Git MV Readme2#Readme2
#git reset --hard HEAD                                                                                                                                                                                                                                                  VEP933 (this branch The changes have been merged into other branches)
git branch -D hotfixes/BJVEP933                                                                                        # List the files included in git index
git show-branch                                                                                                  Branch History
Git Show-BRANCH-ALL#示 All branch history
Git WhatChanged#Show the file to submit the corresponding file modification
Git Revert DFB02E6F2F7B573333763E5C001392818# B02e6e4F2F7B57333763E5C001392818#stess Internal command: display a certain git object
git rev-parse v2.0                                                                                            ​​​​ #Show all commits, including orphan nodes
git show HEAD@ {5}
Git Show Master@{Yesterday}#Display the status of the Master branch of yesterday
Git Log -PRETTY = Format: ' %H %S' -Graph HEAD~3
git show -s --pretty=raw 2be7fcb476
git stash                                                                                                                                          git Stash list#View all the temporary storage
Git Stash Show -P Stash@{0}#Reference the first temporary deposit
Git Stash Apply Stash@{0}# GREP "Delete from"#file Search the text "delete from"
Git Grep -e '#Define' -And -E Sort_dirent
GC



##Git is a very powerful distributed version control system. It is not only suitable for managing the source code of large-scale open source software, but also has many advantages in managing private documents and source code.


Common Git operation commands:

1) Remote warehouse related commands

Check out the warehouse: $ git clone git://github .com/jquery/jquery.git

View remote repository: $ git remote -v

Add remote repository: $ git remote add [name] [url]

Delete Remote warehouse: $ git remote rm [name]

Modify the remote warehouse: $ git remote set-url --push [name] [newUrl]

Pull the remote warehouse: $ git pull [ remoteName] [localBranchName]

Push the remote warehouse: $ git push [remoteName] [localBranchName]

*If you want to submit a local branch test to the remote warehouse , and serve as the master branch of the remote warehouse, or as another branch named test, as follows:

$git push origin test:master //Submit the local test branch as the remote master branch

$git push origin test:test //Submit the local test branch as the remote test branch

2) Commands related to branch operations

View the local branch: $ git branch

View the remote branch: $ git branch -r

Create a local branch: $ git branch [name] ---- Note that the new branch will not automatically switch to the current branch after it is created

Switch branches: $ git checkout [name]

Create a new branch And immediately switch to the new branch: $ git checkout -b [name]

Delete branch: $ git branch -d [name] ---- The -d option can only delete branches that have participated in the merge, for Unmerged branches cannot be deleted. If you want to force delete a branch, you can use the -D option

Merge branch: $ git merge [name] ----Merge the branch named [name] with the current branch

Create Remote branch (local branch pushed to remote): $ git push origin [name]

Delete remote branch: $ git push origin :heads/[name] or $ gitpush origin :[name]

*Create an empty branch: (Remember to submit the modifications to your current branch before executing the command, otherwise it will be forcibly deleted without regrets)

$git symbolic-ref HEAD refs/ heads/[name]

$rm .git/index

$git clean -fdx

3) Commands related to version (tag) operations

View version: $ git tag

Create version: $ git tag [name]

Delete version: $ git tag -d [name]

View remote version: $ git tag -r

Create remote version (local version pushed to remote): $ git push origin [name ]

Delete the remote version: $ git push origin :refs/tags/[name]

Merge the tags of the remote warehouse to the local one: $ git pull origin --tags

Upload local tags to the remote repository: $ git push origin --tags

Create annotated tags: $ git tag -a [name] -m 'yourMessage'

4) Submodule related operation commands

Add submodule: $ git submodule add [url] [path]

For example: $git submodule add git://github.com /soberh/ui-libs.git src/main/webapp/ui-libs

Initialize submodule: $ git submodule init ----Just run it once when checking out the warehouse for the first time

Update submodule: $ git submodule update ----You need to run it every time you update or switch branches

Delete submodule: (step in 4 steps)

1) $ git rm --cached [path]

2) Edit the ".gitmodules" file and delete the relevant configuration nodes of the submodule

3) Edit the ".git/config" file and delete the relevant configuration nodes of the submodule

4) Manually delete the remaining directories of the submodule

5) Ignore some files and folders and do not submit them

Create a name in the root directory of the warehouse with the name ". gitignore" file, write unnecessary folder names or files, each element can occupy one line, such as

target

bin

*.db




##============== ========

Git common commands

git branch View all local branches
git status View current status
git commit submission
git branch -a View all branches
git branch -r View all local branches
git commit -am "init" Submit and add comments
git remote add origin git@192.168.1.119:ndshow
git push origin master Push the file to the server
git remote show origin Display the remote library origin Resources
git push origin master:develop
git push origin master:hb-dev Associate the local library with the library on the server
git checkout --track origin/dev Switch to the remote dev branch
git branch -D master develop Delete the local library develop
git checkout -b dev Create a new local branch dev
git merge origin/dev Merge branch dev with the current branch
git checkout dev Switch to local dev branch
git remote show View remote library
git add .
git rm file name (including path) Delete the specified file from git
git clone git://github.com/schacon/grit .git Pull the code from the server
git config --list to see all users
git ls-files to see what has been submitted
git rm [file name] delete a file
git commit -a Commit all changes to the current repos
git add [file name] Add a file to the git index
git commit -v When you use the -v parameter, you can see the commit differences
git commit - m "This is the message describing the commit" Add commit information
git commit -a -a represents add, add all changes to the git index and then commit
git commit -a -v General commit command
git log View your commit log
git diff View unstaged updates
git rm a.a Remove files (delete from the staging area and workspace)
git rm --cached a.a Remove the file (only delete it from the staging area)
git commit -m "remove" Remove the file (delete it from Git)
git rm -f a.a Forcibly remove the modified file (from the staging area) and delete from the workspace)
git diff --cached or $ git diff --staged to view uncommitted updates
git stash push Push the file to a temporary space
git stash pop Move the file from The temporary space pops down
--------------------------------------------- --------------
git remote add origin git@github.com:username/Hello-World.git
git push origin master Submit the local project to the server
------------------------------------------------ -----------
git pull local and server synchronization
-------------------------- ---------------------------------------
git push (remote warehouse name) ( Branch name) Push the local branch to the server.
git push origin serverfix:awesomebranch
----------------------------------------- ----------------------------
git fetch is equivalent to getting the latest version from the remote to the local, and will not automatically merge
git commit -a -m "log_message" (-a is to submit all changes, -m is to add log information) Local changes are synchronized to the server:
git branch branch_0.1 master creates branch_0.1 branch from the main branch master
git branch -m branch_0.1 branch_1.0 Rename branch_0.1 to branch_1.0
git checkout branch_1.0/master Switch to branch_1.0/master branch
du -hs

------------------------------------------------ -----------
mkdir WebApp
cd WebApp
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git
git push -u origin master

Git common command chart


The above is the detailed content of Introducing the list of commonly used Git commands. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!