Home Backend Development PHP Tutorial Summary of commonly used commands for git operations

Summary of commonly used commands for git operations

Jul 17, 2017 pm 03:11 PM
operate tidy

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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PyCharm usage tutorial: guide you in detail to run the operation PyCharm usage tutorial: guide you in detail to run the operation Feb 26, 2024 pm 05:51 PM

PyCharm is a very popular Python integrated development environment (IDE). It provides a wealth of functions and tools to make Python development more efficient and convenient. This article will introduce you to the basic operation methods of PyCharm and provide specific code examples to help readers quickly get started and become proficient in operating the tool. 1. Download and install PyCharm First, we need to go to the PyCharm official website (https://www.jetbrains.com/pyc

What is sudo and why is it important? What is sudo and why is it important? Feb 21, 2024 pm 07:01 PM

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and

Linux Deploy operation steps and precautions Linux Deploy operation steps and precautions Mar 14, 2024 pm 03:03 PM

LinuxDeploy operating steps and precautions LinuxDeploy is a powerful tool that can help users quickly deploy various Linux distributions on Android devices, allowing users to experience a complete Linux system on their mobile devices. This article will introduce the operating steps and precautions of LinuxDeploy in detail, and provide specific code examples to help readers better use this tool. Operation steps: Install LinuxDeploy: First, install

What to do if you forget to press F2 for win10 boot password What to do if you forget to press F2 for win10 boot password Feb 28, 2024 am 08:31 AM

Presumably many users have several unused computers at home, and they have completely forgotten the power-on password because they have not been used for a long time, so they would like to know what to do if they forget the password? Then let’s take a look together. What to do if you forget to press F2 for win10 boot password? 1. Press the power button of the computer, and then press F2 when turning on the computer (different computer brands have different buttons to enter the BIOS). 2. In the bios interface, find the security option (the location may be different for different brands of computers). Usually in the settings menu at the top. 3. Then find the SupervisorPassword option and click it. 4. At this time, the user can see his password, and at the same time find the Enabled next to it and switch it to Dis.

How to disable the action button on iPhone 15 Pro and 15 Pro Max How to disable the action button on iPhone 15 Pro and 15 Pro Max Nov 07, 2023 am 11:17 AM

Apple brought some Pro-exclusive hardware features to iPhone 15 Pro and 15 Pro Max, which attracted everyone’s attention. We're talking titanium frames, sleek designs, the new A17 Pro chipset, an exciting 5x telephoto lens, and more. Of all the bells and whistles added to the iPhone 15 Pro models, the action button remains a prominent and prominent feature. Needless to say, it is a useful addition to launching actions on your iPhone. That said, you could accidentally hold down the Action button and trigger the feature inadvertently. Frankly, it's annoying. To avoid this, you should disable the action button on iPhone 15 Pro and 15 Pro Max. let

Huawei Mate60 Pro screenshot operation steps sharing Huawei Mate60 Pro screenshot operation steps sharing Mar 23, 2024 am 11:15 AM

With the popularity of smartphones, the screenshot function has become one of the essential skills for daily use of mobile phones. As one of Huawei's flagship mobile phones, Huawei Mate60Pro's screenshot function has naturally attracted much attention from users. Today, we will share the screenshot operation steps of Huawei Mate60Pro mobile phone, so that everyone can take screenshots more conveniently. First of all, Huawei Mate60Pro mobile phone provides a variety of screenshot methods, and you can choose the method that suits you according to your personal habits. The following is a detailed introduction to several commonly used interceptions:

CSS web page scroll monitoring: monitor web page scroll events and perform corresponding operations CSS web page scroll monitoring: monitor web page scroll events and perform corresponding operations Nov 18, 2023 am 10:35 AM

CSS web page scroll monitoring: monitor web page scroll events and perform corresponding operations. With the continuous development of front-end technology, the effects and interactions of web pages are becoming more and more rich and diverse. Among them, scroll monitoring is a common technology that can perform some special effects or operations based on the scroll position when the user scrolls the web page. Generally speaking, scroll monitoring can be implemented through JavaScript. However, in some cases, we can also achieve the effect of scroll monitoring through pure CSS. This article will introduce how to implement scrolling of web pages through CSS

Custom Action Buttons: Explore Personalization on iPhone 15 Pro Custom Action Buttons: Explore Personalization on iPhone 15 Pro Sep 24, 2023 pm 03:05 PM

Apple's iPhone 15 Pro and iPhone 15 Pro Max introduce a new programmable action button that replaces the traditional ring/silent switch above the volume buttons. Read on to learn what the Action button does and how to customize it. A new action button on Apple iPhone 15 Pro models replaces the traditional iPhone switch that activates Ring and Silent. By default, the new button will still activate both functions with a long press, but you can also have a long press perform a range of other functions, including quick access to the camera or flashlight, activating voice memos, focus mode, translation, and accessibility features like magnifier . You can also associate it with a single shortcut, opening up a ton of other possibilities

See all articles