search
HomeBackend DevelopmentPHP TutorialSummary of commonly used commands for git operations

Commonly used commands Summary

一 1. Return to a certain node and pass the following command:

– Modifications such as:

Git reset –hard HASH returns to a certain node and retains the modifications.

2. All local modifications. Anything that has not been submitted will be returned to its original state.

Git checkout .

Git checkout repository means switching the repository, such as: git checkout dev switches to the dev repository

Git checkout file address means canceling the modification of the file, such as :git checkout backend/controller/site

3. View the commit log

Git log

4. View the branch

Git branch without parameters: column Exit the local branch. There will be an * sign in front of the current branch. 5. Dealing with the LF problem As follows:

Configure global variables git config --global core.autocrlf false

View global variables git config –global –l to view global variables

mkdir learngit //Create A folder

cd learngit //Switch the current directory

pwd //Display the full path of the current directory

git init //Initialize the directory

ls - ah //Display all files in the current directory, including hidden files

cd.>readme.txt //Create an empty file

git add readme.txt //Add the file to the git repository

git commit -m “wrote a readme file” //Submit the file and add the change description

git status //View the change status of the current warehouse file

git diff / / is a comparison between the work area (work dict) and the temporary storage area (stage)

git diff --cached // is a comparison between the temporary storage area (stage) and the branch (master)

After modifying the file content, git status will prompt use "git add" and/or "git commit -a". Please add first and then commit. You cannot commit directly.

git log //View git submission record, including time and Submitter and other detailed information

git log --pretty=oneline //Only view the version number and submission description

git reset --hard HEAD^ //Roll back the previous version

git reset --hard HEAD^^ //Rollback to the previous version

git reset --hard HEAD~100 //Rollback to the previous 100 versions

git reset - -soft HEAD //Do not reset the cache area and workspace when rolling back

git reset --mixed HEAD //Reset the cache area when rolling back, default option

git reset -- hard HEAD //Reset the cache area and work area when rolling back

git reset //No HEAD specified, used to clear the cache area modifications

git reset filename //Clear the cache area specified File modification

git reset --hard //Do not specify HEAD, used to clear the workspace and cache area.

git reset --hard filename //Clear the workspace and cache area Modification of the specified file

cat readme.txt //View file content

If you want to withdraw after rolling back, there are two ways

1) You need to retrieve the latest version number without closing the original terminal window, enter the first few digits, for example

git reset --hard ec6980a

2) Close the terminal window and reopen it , enter git reflog, view each record of the operation, retrieve the version number and roll back

git checkout -- file //Undo the workspace operation, there are two situations, 1、Not Before adding to the cache area, the local workspace modifications are undone. 2. After the cache area has been added, the cached modifications are undone and the cached version is restored.

git checkout -- -- in the file command is very important , without --, it becomes a "switch to another branch" command

git checkout branch //Switch branch, reset the cache area and work area at the same time, if the work area has been modified but not submitted, it is necessary Commit or stash first

git checkout branch --force //Switch branch, reset cache area and work area at the same time

git checkout --force //Not specify branch, used to clear work Modification of the area (the cache area remains unchanged, if there was an add before, the work area is consistent with the cache area)

git reset HEAD fileName //You can undo the modifications to the temporary storage area ( unstage)

rm test.txt //Delete the file on the file manager, please note that the local deletion must correspond to the warehouse

git rm text.txt //Delete the remote Warehouse file, then submit git commit

git checkout -- test.txt //Suppose the local rm deletes the file by mistake, you can use the command to copy the latest copy from the warehouse to the local, and replace the workspace version with the version in the repository, regardless of whether the workspace is modified or Deleted, you can "restore it with one click"

ssh-keygen -t rsa -C "liwenxin@foreveross.com" //Set the locally associated account information, press Enter all the way, no Set the password directly to blank.

open ~/.ssh //mac opens ssh in the home directory

cd ~/.ssh //If you accidentally entered the password in the previous steps, you can reset it to empty by following the following methods Password

ssh-keygen -p -f id_rsa //Enter the old password once and the new password twice as required

git remote add origin git@github.com:gz -jam/learngit.git //Replace with your own GitHub account name and associate the remote library locally

git remote rm origin //If the association is wrong or needs to be rebind

git remote add origin git@github.com:michaelliao/learngit.git //You can rebind

git push -u origin master //Push all the contents of the local library to the remote library, enter Confirm yes and push the current branch master to the remote. Since the remote library is empty, when we pushed the master branch for the first time, we added the -u parameter. Git will not only push the contents of the local master branch to the remote new master branch , it will also associate the local master branch with the remote master branch, which can simplify the commands when pushing or pulling in the future.

git push origin master //You don’t need to -u

git clone git@github.com:michaelliao/gitskills.git //Clone the remote warehouse ,Git supports multiple protocols. The default git:// uses ssh, but other protocols such as https can also be used. For example https://github.com/gz-jam/gitskills.git

git checkout -b dev //Create a branch and switch the current branch to dev, which is equivalent to executing two Instructions, such as git branch dev and git checkout dev

git branch //View all branches of the current project, the * in front represents the currently effective branch

git merge dev //For merge specification Branch to the current branch

git branch -d dev //After merging, you can consider deleting redundant project branches

git branch -D dev //The branch submission file has not been merged. If deleted, it will prompt that it has not yet been merged. , do you want to force delete? Note the capital D

When both branches have submission content in the same file, Git cannot perform "quick merge". At this time, you need to execute git status first. Git uses >>>>>> Mark the contents of different branches, and re-git add the file after adjustment. Then git commit submits the file to resolve the conflict

git log --graph --pretty=oneline --abbrev-commit //You can see the merge status of the branch

git log --graph //This command can also see the branch merge diagram

git merge --no-ff -m "merge with no-ff" dev //Disable Fast forward mode, Git will Generate a new commit during merge

git stash //The current branch work is not completed but you don’t want to submit it to the warehouse. You can save it with instructions first to ensure that switching to other branches will not cause code loss.

git stash list //View the stash content. There are two recovery methods. One is to use git stash apply stash@{0} to recover. However, after recovery, the stash content is not deleted. You need to use git stash. drop to delete; another way is to use git stash pop, which deletes the stash content while restoring

git remote //View the information of the remote library

git remote -v //Display more detailed information

git push origin master //Pushing a branch means pushing all local submissions on the branch to the remote library. When pushing, you must specify the local branch

If the newly created local branch is not pushed to the remote, it will not be visible to others.

To push the branch locally, use git push origin branch-name

git checkout -b dev origin /dev //Create the dev branch of the remote origin to the local, the default branch master

git push //When a conflict occurs, first git pull the code

git pull //If it fails, it will prompt "no tracking information". The reason may be that the link between the local dev branch and the remote origin/dev branch is not specified

git branch --set-upstream-to=origin/dev dev //Set the link between dev and origin/dev

There is a conflict in the merge and needs to be resolved manually. The solution is as mentioned above, git status, then manually repair, then git add and git commit, and finally git push

git tag v1.0 //The commit number is too long to remember, you can tag it on the branch

git tag v0.9 6224937 //On the branch it is The specified commit numbers are tagged

. The tags are not listed in chronological order, but in alphabetical order. You can use git show to view tag information

For example git show v0.9

git tag -a v0.1 -m "version 0.1 released" 3628164 //Create with description For tags, use -a to specify the tag name and -m to specify the description text

git tag -d v0.1 //If the tag is mistyped, you can also delete it

The created tags are only stored locally and will not be automatically pushed to the remote. If you want to push a tag to the remote, use the command git push origin

For example: git push origin v1.0

Or, push all the locals that have not been pushed to the remote at once Tag

For example: git push origin --tags

If the tag has been pushed to the remote, it is a little more troublesome to delete the remote tag. First delete it locally, git tag -d v0.9; then , delete from remote. The delete command is also push, but the format is as follows git push origin :refs/tags/v0.9 or git push origin --delete tag v0.9

The above is the detailed content of Summary of commonly used commands for git operations. 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
PHP编程中有哪些常见的Behat操作?PHP编程中有哪些常见的Behat操作?Jun 12, 2023 am 08:19 AM

PHP编程中有哪些常见的Behat操作?Behat是一个行为驱动开发(BDD)工具,允许测试人员和开发人员在自然语言中撰写测试用例,并将这些用例转化为可执行的代码。它支持PHP语言,并提供了丰富的库和功能,可以实现多种常见的测试操作。下面列举了PHP编程中常见的Behat操作。前置条件(Background)在编写测试用例时,有时候会有一些公共的前置条件需要

ThinkPHP6如何进行表单验证操作?ThinkPHP6如何进行表单验证操作?Jun 12, 2023 am 09:36 AM

ThinkPHP6是一款基于PHP的MVC框架,极大地简化了Web应用程序的开发。其中表单验证是一个非常基础和重要的功能。在这篇文章中,我们将介绍ThinkPHP6中如何进行表单验证操作。一、验证规则定义在ThinkPHP6中,验证规则都需要定义在控制器中,我们可以通过在控制器中定义一个$validate属性来实现规则的定义,如下所示:usethinkVa

Win10桌面图标整理技巧Win10桌面图标整理技巧Dec 27, 2023 pm 05:00 PM

使用电脑的小伙伴都希望自己的桌面排列干净看起来整整齐齐但是不知道怎么在win10系统中操作,今天就给你们带来了整理桌面图标win10方法,一起看看吧。整理桌面图标win10怎么整齐:1、右击桌面空白处,点击最上方的“查看”。2、在右侧的窗口中可以看到“自动排列图标”等功能。3、不要勾选“自动排列图标”这样就能够根据自己的需求来摆放图标了。4、而且这些选项是都可以全部选择的,但是这样就没法摆出自己的个性了。

win10系统如何整理磁盘碎片win10系统如何整理磁盘碎片Jun 29, 2023 pm 07:41 PM

  win10系统如何整理磁盘碎片?随着电脑的使用率越来越高,我们有时候可能会遇到对win10系统整理磁盘碎片进行设置,如果我们需要对win10系统整理磁盘碎片进行设置时,要怎么处理win10系统整理磁盘碎片呢?很多小伙伴不知道怎操作,小编下面整理了win10系统整理磁盘碎片的详细步骤,如果你感兴趣的话,跟着小编一起往下看看吧!  win10系统整理磁盘碎片的详细步骤:  1.什么样的磁盘需要整理  我们要知道,并不是所有的磁盘都是需要进行碎片整理的,比如非常常见的固态硬盘和移动磁盘类设备。  

PHP编程中有哪些常见的jQuery操作?PHP编程中有哪些常见的jQuery操作?Jun 12, 2023 am 10:38 AM

PHP编程中有哪些常见的jQuery操作?在PHP编程中,使用jQuery进行网页开发是一种非常方便和高效的方式。jQuery是一个简单而强大的JavaScript库,包含了许多实用的方法和函数。在PHP编程中,我们常常使用jQuery来操纵HTML和DOM元素,使网页具有更好的交互性和高度的可视化效果。在本文中,我们将介绍一些常见的PHP编程中使用jQue

PHP编程中有哪些常见的OAuth操作?PHP编程中有哪些常见的OAuth操作?Jun 12, 2023 am 08:48 AM

OAuth(开放授权)是一种用于授权访问控制的标准化协议。在Web开发中,使用OAuth可以帮助应用程序安全地从第三方平台中获取用户数据或资源。而在PHP编程中,OAuth操作也被广泛应用。本文将介绍PHP编程中的常见OAuth操作。OAuth1.0a授权OAuth1.0a授权是OAuth中最早出现的授权方式,也是最复杂的一种授权方式。在PHP编程中,O

怎样使用ThinkPHP6进行多语言翻译操作?怎样使用ThinkPHP6进行多语言翻译操作?Jun 12, 2023 am 08:49 AM

随着全球化的发展,越来越多的网站和应用程序需要提供多语言支持。而对于使用ThinkPHP6框架的开发者来说,如何实现多语言翻译操作是一个重要的需求。本文将介绍怎样使用ThinkPHP6进行多语言翻译操作。配置语言包在ThinkPHP6中,语言包是一个包含键值对的数组。可以将其存储在app/lang/目录下的各种子目录中。例如:/app/lang/zh-cn/

PHP编程中有哪些常见的Ajax操作?PHP编程中有哪些常见的Ajax操作?Jun 12, 2023 am 08:26 AM

随着Web应用程序的发展,Ajax成为了一种重要的技术,在PHP编程中也得到了广泛的应用。通过Ajax技术,Web应用程序可以实现异步操作,从而提高了用户体验和应用程序性能。在本文中,我们将探讨PHP编程中常见的Ajax操作。一、Ajax基础知识在介绍常见的Ajax操作之前,我们先来了解一下Ajax技术的基础知识。Ajax全称为"AsynchronousJ

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor