search
HomeWeb Front-endJS TutorialSummary of common Git commands

Summary of common Git commands

Jul 18, 2017 pm 05:59 PM
Encyclopediapromotefast

Remote warehouse related commands

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

View the remote warehouse: $ git remote -v

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

Delete remote repository: $ git remote rm [name]

Modify remote repository: $ 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 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

Initialize the local git warehouse (create a new warehouse)

git init


Configure user name

git config --global user.name "xxx"

Configuration email

git config --global user.email "xxx@xxx.com"

git status and other commands automatically color

git config --global color.ui true                  
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto


clone remote warehouse

git clone git+ssh://git@192.168.53.168/VT.git

Branch operation related commands

View local branches: $ 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 switch to the new branch immediately: $ git checkout -b [name]

Delete a branch: $ git branch -d [name] ---- The -d option can only delete branches that have participated in the merge, and cannot delete branches that 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


View the current version status (whether modified)

git status


Add xyz file to index

git add xyz


Add all changed files in the current subdirectory to index

git add .


Commit

git commit -m 'xxx'


Merge the last commit (for repeated modifications)

git commit --amend -m 'xxx'


Combine add and commit in one step

git commit -am 'xxx'


Delete files in index

git rm xxx


Recursive deletion

git rm -r *


Display commit Log

git log


Display 1 line of log -n is n line

git log -1                                    
git log -5

##Display the commit log and related change files

git log --stat


#Display the details of a commit

git show dfb02e6e4f2f7b573337763e5c0013802e392818

You can only use the first few digits of the commitid

git show dfb02

Display HEAD commit log

git show HEAD

Display HEAD The commit log of the parent (previous version) ^^ is the previous two versions ^5 is the previous 5 versions

git show HEAD^

display Existing tag

git tag

Add v2.0 tag

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

Show v2.0 logs and details

git show v2.0

Display v2.0 log

git log v2.0

Display all changes that have not been added to the index

git diff


Display all changes that have been indexed but not yet committed

git diff --cached


Compare with the previous one Version difference

git diff HEAD^


Compare the difference with the HEAD version lib directory

git diff HEAD -- ./lib


Compare the remote branch master to the local branch master that is not present

git diff origin/master..master


Only displays the difference files, not the specific content

git diff origin/master..master --stat


Add remote Definition (for push/pull/fetch)

git remote add origin git+ssh://git@192.168.53.168/VT.git


Show local branch

git branch


Show branch containing commit 50089

git branch --contains 50089


Show all branches

git branch -a


Show all original branches

git branch -r


Displays all branches that have been merged into the current branch

git branch --merged


Display all branches that have not been merged into the current branch

git branch --no-merged


Local branch rename

git branch -m master master_copy


Create a new branch master_copy from the current branch and checkout

git checkout -b master_copy


Full version of the above

git checkout -b master master_copy


Check out the existing features/performance branch

git checkout features/performance


Check out the remote branch hotfixes/BJVEP933 and create a local tracking branch

git checkout --track hotfixes/BJVEP933


Checkout version v2.0

git checkout v2.0


Create a new local branch from the remote branch develop devel and checkout

git checkout -b devel origin/develop


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

git checkout -- README


Merge the remote master branch to the current branch

git merge origin/master

Merge the changes to commit ff44785404a8e

git cherry-pick ff44785404a8e


Push the current branch to the remote master branch

git push origin master


Delete the hotfixes/BJVEP933 branch of the remote warehouse

git push origin :hotfixes/BJVEP933


Push all tags to the remote repository

git push --tags


Get all remote branches (do not update local branches, Merge is required)

git fetch


Get all original branches and clear deleted branches on the server

git fetch --prune


Get the remote branch master and merge it to the current branch

git pull origin master

## Rename the file README to README2

git mv README README2

Reset the current version to HEAD (usually used for merge failure rollback)

git reset --hard HEAD                                                                                

git rebase

##Delete branch hotfixes/BJVEP933 (modifications of this branch have been merged into other branches)


git branch -d hotfixes/BJVEP933


Force deletion of branch hotfixes/BJVEP933

git branch -D hotfixes/BJVEP933


List the files included in git index

git ls-files


Illustration of the current branch history

git show-branch

Illustrated history of all branches


git show-branch --all

Show the file modifications corresponding to the submission history


##Undo the submission dfb02e6e4f2f7b573337763e5c0013802e392818

##git revert dfb02e6e4f2f7b573337763e5c0013802e3 92818


Internal command: display a certain git object

git ls-tree HEAD


Internal command: display a certain ref for SHA1 HASH

git rev-parse v2.0


Show all commits, including orphaned nodes

git reflog                                                  

git show HEAD@{5}


Show the status of the master branch yesterday


git show master@{yesterday}


Image submission log

git log --pretty=format:'%h %s' --graph
git show HEAD~3
git show -s --pretty=raw 2be7fcb476


Store the current modifications and move all to HEAD status

git stash


View all temporary saves

git stash list


Refer to the first stash

git stash show -p stash@{0}


Apply the first stash

git stash apply stash@{0}


Search for the text "delete from" in the file

git grep "delete from"                                      
git grep -e '#define' --and -e SORT_DIRENT
git gc
git fsck

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

Statement
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
JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.