Home >Development Tools >git >Summary of git commonly used commands

Summary of git commonly used commands

coldplay.xixi
coldplay.xixiforward
2020-12-17 17:28:543219browse

Git TutorialThe column introduces commonly used git commands

Summary of git commonly used commands

Recommended (free ): Git tutorial

1. Quick check of common Git commands

git branch View all local branches

git status View the current status

git commit submission

git branch -a View all branches

git branch -r View all remote branches

git commit -am "init" commit 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 to display the remote library Resources in origin

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 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 submitted files

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 You can see the commit differences when you use the -v parameter

git commit -m "This is the message describing the commit" Add commit information

git commit -a -a means add, add all changes 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 (delete from the staging area only)

git commit -m "remove" Remove files (delete from Git)

git rm -f a.a Forcefully remove modified files (delete from staging area and workspace)

git diff --cached or $ git diff --staged 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 remote Local, will not merge automatically

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 Create branch_0.1 branch from master 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 the remote server

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 the URL address to 'git@github.com:daixu/ WebApp.git', a remote server library named origin. When submitting code in the future, you only need to use the origin alias

2. Git command cheat sheet

1. Commonly used Git commands

Command brief description

git add to the staging area

git add–interactive interactive addition

git apply application patch

git am applies email format patch

git annotate synonym, equivalent to git blame

git archive file archive packaging

git bisect binary search

git blame File traceability line by line

git branch branch management

git cat-file repository object research tool

git checkout checkout to the workspace, switch or create a branch

git cherry-pick submission selection

git citool graphical submission, equivalent to the git gui command

git clean clears untracked files in the workspace

git clone clone version Library

git commit submission

git config query and modify configuration

git describe visually displays the commit ID through milestones

git diff difference comparison

git difftool calls the graphical difference comparison tool

git fetch to obtain the commit of the remote repository

git format-patch creates a patch file in email format. See git am command

git grep file content search and location tool

git gui is a graphical tool based on Tcl/Tk, focusing on operations such as submission

git help

git init repository initialization

git init-db* synonym, equivalent to git init

git log displays the commit log

git merge branch merge

git mergetool graphical conflict resolution

git mv rename

git pull pulls back the submission of the remote repository

git push to the remote repository

git rebase branch rebase

git rebase–interactive interactive branch rebase

git reflog branch and other reference change record management

git remote remote version library management

git repo-config* Synonyms, equivalent to git config

git reset resets the change branch "cursor" pointing to

git rev-parse converts various reference representations to Ha Hope value, etc.

git revert reverse commit

git rm delete file

git show displays various types of objects

git stage*Synonyms, equivalent Save and restore progress in git add

git stash

git status displays workspace file status

git tag milestone management

2. Object library operations related Command

Command brief description

git commit-tree creates a commit from a tree object

git hash-object calculates a hash value or creates an object from standard input or a file

git ls-files displays the workspace and staging area files

git ls-tree displays the files contained in the tree object

git mktag reads the standard input and creates a milestone object

git mktree reads the standard input and creates a tree object

git read-tree reads the tree object to the temporary storage area

git update-index The content of the workspace is registered to the temporary storage area and Staging area management

git unpack-file creates a temporary file containing the contents of the specified blob

git write-tree creates a tree object from the staging area

3. Reference operation Related commands

Command brief description

git check-ref-format checks whether the reference name conforms to the specification

git for-each-ref reference iterator, used for shell programming

git ls-remote displays references to remote repositories

git name-rev displays commit IDs as friendly names

git peek-remote* Obsolete command, please use git ls -remote

git rev-list displays the version range

git show-branch displays the branch list and topological relationship

git show-ref displays local references

git symbolic-ref displays or sets the symbolic reference

git update-ref updates the reference pointing to

git verify-tag verifies the GPG signature Tag

4. Repository management Related commands

Command brief description

git count-objects displays the number of loose objects and disk usage

git filter-branch version library reconstruction

git fsck object library integrity check

git fsck-objects* synonym, equivalent to git fsck

git gc version library storage optimization

git index-pack creates the corresponding file from the packaged file The index file

git lost-found* is out of date, please use the git fsck –lost-found command

git pack-objects reads the object ID from the standard input and packs it into the file

git pack-redundant finds redundant pack files

git pack-refs packs references into .git/packed-refs files

git prune deletes expired objects from the object library

git prune-packed deletes loose objects that have been packaged

git relink establishes a hard connection for the same object in the local repository

git repack packs unpacked loose objects in the repository

git show-index reads the index file of the package and displays the contents of the package file

git unpack-objects releases the file from the package file

git verify-pack verification Object library packaging file

5. Data transmission related commands

Brief description of command

git fetch-pack executes this command locally when executing the git fetch or git pull command. Use Used to obtain missing objects from other repositories

git receive-pack is a command that is executed remotely when executing the git push command, and is used to receive pushed data

git send-pack executes the git push command A command that is executed locally and used to push data to other repositories

git upload-archive executes the git archive –remote command to create an archive based on the remote repository, and the remote repository executes this command to transfer the archive

git upload-pack executes this command remotely when executing the git fetch or git pull command to package and upload the object

6, email related commands

Brief description of the command

git imap-send sends the patch through IMAP

git mailinfo exports submission instructions and patches from the email

git mailsplit extracts the emails in the mbox or Maildir format mailbox one by one into files

git request-pull creates information containing the differences between submissions and the address for performing the PULL operation

git send-emailSend an email

7. Protocol-related commands

Brief description of the command

git daemon implements the Git protocol

git http-backend implements the CGI program of the HTTP protocol and supports the intelligent HTTP protocol

git instaweb instantly starts the browser and browses the current version library through gitweb

git shell A restricted shell that provides SSH access to execute only Git commands

git update-server-info updates the auxiliary files required for the dumb protocol

git http-fetch obtains the repository through HTTP protocol

git http-push pushes through HTTP/DAV protocol

git remote-ext is called by the Git command and provides extended protocol support through external commands

git remote-fd is called by the Git command and uses the file descriptor as the protocol interface

git remote -ftp is called by the Git command, providing support for the FTP protocol

git remote-ftps is called by the Git command, providing support for the FTPS protocol

git remote-http is called by the Git command, providing support Support for HTTP protocol

git remote-https is called by Git command and provides support for HTTPS protocol

git remote-testgit protocol extension sample script

8, version library Conversion and interaction related commands

Brief description of commands

git archimport imports Arch repository into Git

git bundle submits packaging and unpacking for transfer between different repositories

git cvsexportcommit checks out a Git commit as a CVS

git cvsimport imports the CVS repository into Git. Or use cvs2git

git cvsserverGit's CVS protocol simulator, which can be used by CVS commands to access the Git repository

git fast-export exports submissions to git-fast-import format

git fast-import A universal tool for migrating other repositories to Git

git svnGit as a front-end operation Subversion

9, merge related auxiliary commands

Brief description of commands

git merge-base is called by other scripts to find the nearest common ancestor of two or more commits

git merge-file performs a three-way file merge against two different versions of a file

git merge-index calls the specified conflict resolution tool for conflict files in the index

git merge-octopus merges two or more branches. See git merge's octopus merge strategy

git merge-one-file Standard helper called by git merge-index

git merge-ours merge using the local version and discarding other people's versions. See ours merge strategy for git merge

git merge-recursive for a three-way merge of two branches. See git merge's recursive merge strategy

git merge-resolve for a three-way merge of two branches. See git merge's resolve merge strategy

git merge-subtree subtree merge. See the subtree merge strategy of git merge

git merge-tree explicit three-way merge results, without changing the temporary storage area

git fmt-merge-msg is used for script calls to perform merge operations. Instructions for creating a merge commit

git rerereuse recorded conflict resolution

10. Miscellaneous

Command brief description

git bisect–helper by The git bisect command is called to confirm the binary search progress

git check-attr displays whether a certain file has a certain attribute set

git checkout-index copies the file from the temporary storage area to the workspace

git cherry searches for commits that have not been merged into the upstream

git diff-files compares the staging area and the work area, which is equivalent to git diff –raw

git diff-index compares the staging area Area and repository, equivalent to git diff –cached –raw

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

git difftool-helper is commanded by git difftool Called, the default difference comparison tool to be used

git get-tar-commit-id extracts the commit ID from the tar package created by git archive

git gui–askpass command git gui Get user Password input interface

git notes submission comment management

git patch-id patch filters line numbers and blank characters to generate a unique patch ID

git quiltimport applies the Quilt patch list to Current branch

git replace submits and replaces

git shortlog's summary output of git log, suitable for product release instructions

git stripspace deletes empty lines for other script calls

git submodule submodule management

git tar-tree outdated command, please use git archive

git var displays Git environment variables

git web–browse startup Browser to view directories or files

git whatchanged displays the commit history and changes of each commit

git-mergetool–lib is included in other scripts and provides selection and comparison of merge/diff comparison tools Execution

git-parse-remote is included in other scripts, providing functions for operating remote repositories

git-sh-setup is included in other scripts, providing function libraries for shell programming

Git Command Reference Manual (Text Version)

git init                                                             "xxx"#Configure user name

# Git Config -Global User.email "xxx@xxx.com"#Configure email

Git Config -Global Color.ui True#Git Status and other commands automatically colored

iglobal Color.status auto

QIT Config -Global Color.diff Auto

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                                                                                                                         # Add xyz files to index

git add .                                                                        All changed files in the directory to index

git commit -m 'xxx' # Commit

git commit --amend -m 'xxx' # Merge the last commit (for repeated modifications) )

Git Commit -AM 'XXX'##)))))

# x x xxx#Delete files

)))))) Delete

git log                                                                                                                                                                                               to Line log -n is n lines

git log -5

git log --stat                                                                                                                                                                           Display the details of a commit

git show dfb02 # You can only use the first few digits of commitid

git show HEAD                                                                                                                                          

git show HEAD^                                                                                                                                                                                                             # Display existing tags

git tag -a v2.0 -m 'xxx'                                                                                                                                                                                          because Details

git log v2.0                                                                                                                                                                                          Changes

git diff --cached                                                                                                          Change

Git Diff Head^#Comparison with the previous version of the difference

# Git Diff Head- ./lib#Comparison with the Head version lib directory

Git diff origin/master..master                                                                                                                                                                                                                                                                     through

#git remote add origin git ssh://git@192.168.53.168/VT.git # Add remote definition (for push/pull/fetch)

git branch                                                                                                     

Git Branch -CONTAINS 50089#Show the branch containing a branch of 50089

-a#shows all branches

--R# #git branch --merged #Display all branches that have been merged into the current branch

git branch --no-merged                                                                                                                                                                                                                                                                                                                                                                                           Branch to create a new branch master_copy and check out

git checkout -b master master_copy                                                                                                                                                                                     # The complete version ## Git Checkout -Track Hotfixes/Bjvep933#detects the remote branch HOTFIXES/BJVEP933 and create a local tracking branch. b devel origin/develop # Create a new local branch devel from the remote branch develop and check it out

git checkout -- README # Check out the README file of the head version (can be used to modify error rollback)

Git Merge Origin/Master#merged remote Master branch to the current branch

stere-Pick FF44785404A8E#Modification of FF44785404A8E Modification

##Qit Push Master#, push the current branch push to far away Cheng Master branch

git push origin :hotfixes/BJVEP933                                                                                                                                                                                                                                                      

##git fetch                                                                         Get all remote branches (do not update local branches, merge is required)

git fetch --prune                                                                                                                       # Get the remote branch master and merge it into the current branch

git mv README README2  

git reset --hard HEAD                                                                                                                                                                                                                                        hotfixes/BJVEP933 (modifications in this branch have been merged into other branches)

git branch -D hotfixes/BJVEP933                                                                                             ​​​​​​​​File

文 文 文 文#图 文 示 文 文

文 文-— all#示 All branch history

文File modification

git revert dfb02e6e4f2f7b573337763e5c0013802e392818 #Revoke submission dfb02e6e4f2f7b573337763e5c0013802e392818

git ls-tree HEAD                                                                                                                                                                                                                          Since Command: Show the SHA1 HASH of a certain ref

git reflog      yesterday}                            # Display the status of the master branch yesterday

git log --pretty=format:'%h %s' --graph                                                             # Show the status of the master branch yesterday

git log --pretty=format:'%h %s' --graph            # Illustrated commit log

git show HEAD~3

git show -s --pretty=raw 2be7fcb476

git stash                                                                                                                                                                                                                                but  

# Git Stash Show -P Stash@{0}#Refer to the first temporary deposit

Git Stash Apply Stash@{0}#

Git Grep "Delete from"#File Search the text "Delete from"

# Git Grep -e '#Define' -And -E Sort_dirent

##git fsck

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 operating 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 repository: $ 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 use it as the master branch of the remote warehouse, or as another branch named The branch of test is 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 master branch Remote test branch

2) Branch operation related commands

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 already participated in the merge Branches cannot be deleted if they have not been merged. 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) Version (tag) operation related commands

View version: $ git tag

Create version: $ git tag [name]

Delete version: $ git tag -d [name]

View remote version: $ git tag -r

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

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

Merge remote Warehouse tags to local: $ git pull origin --tags

Upload local tags to remote warehouse: $ 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 ----Only in Just run it once when you check out the warehouse for the first time

Update submodule: $ git submodule update ----You need to run it every time after updating or switching branches

Delete submodule: (Minute 4 Step by step)

1) $ git rm --cached [path]

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

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 Do not submit

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

target

bin

*.db

=====================

Git Commonly used 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 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 resources in the remote library origin

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 from the server Pull down the code

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 commits all changes to the current repos

git add [file name] adds a file to the git index

git commit -v When you use the -v parameter You can see the difference between commits

git commit -m "This is the message describing the commit" Add commit information

git commit -a -a means add, adding all changes Go to the git index and then commit

git commit -a -v general commit command

git log to see your commit log

git diff to view the updates that have not been staged

git rm a.a Remove files (delete from the staging area and workspace)

git rm --cached a.a Remove files (delete from the staging area only)

git commit -m "remove" removes the file (delete from Git)

git rm -f a.a forcibly removes the modified file (delete from the staging area and workspace)

git diff --cached or $ git diff --staged View uncommitted updates

git stash push Push the file to a temporary space

git stash pop Move the file from the temporary space The space pops down

------------------------------------------------ ----------------

git remote add origin git@github.com:username/Hello-World.git

git push origin master will Submit local projects 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 remote Local, will not merge automatically

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 Create branch_0.1 branch from master 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

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

Statement:
This article is reproduced at:jianshu.com. If there is any infringement, please contact admin@php.cn delete