Some of the differences between git checkout and git reset and configure git shorthand commands _git

Source: Internet
Author: User
I. BACKGROUND

When debugging code, every time through git upload to the server debugging, it is a very troublesome thing. So for some minor changes, I'm going to modify it directly on the server. After debugging successful, with Git reset and then back to the previous version, and then after the boss to remind, only to find the use of git checkout simpler, and do not have to back up the version. Two, git reset fallback version

1, back to the previous version

Command: Git reset–hard head^
The ^ here represents the fall back to the previous version.

2, fall back to the development version

Command: Git Reset–hard + Submit version number
Explanation: The submitted version number here refers to the yellow hash value after the commit after git log.

3, why not choose to use git reset

# # title # #git Reset is the version before you fall back to commit. And we are in the server directly modify the code, there is no commit situation. So it doesn't look right to use git reset. And this command is prone to error, in the event of a rollback version error, it is not good

Third, Git checkout

1, git checkout--check out, is our common command. Often used to switch branches, here is another use of git checkout.

2, Git checkout. Title

Action: Cancels all previous uncommitted modifications under the current directory. That is, we can use this command to cancel the previous modification before we change the code, but without a commit.

3, Git checkout a/abc

Explanation: The a/abc here refers to the directory structure. The meaning of this command is to cancel all changes to the ABC file in the A directory. That is to say git checkout can be specific to a directory and cancel the modification.

Iv. about configuring Git shorthand commands

In the following command, a few abbreviations are used to illustrate:

Git St # git status
Git ci # git commit
git br # git branch
Git Co # git checkout
git mg # git merge
git line # git log–oneline
Of course, you can also simply tap the commands in git to add these abbreviations to the GIT configuration

Git config–global-e
You can then insert the following configuration:

Copy Code
[Alias]
St = Status
CO = Checkout
BR = Branch
MG = Merge
CI = Commit
MD = Commit–amend
DT = Difftool
MT = Mergetool
Last = Log-1 Head
cf = Config
line = Log–oneline
Latest = for-each-ref–sort=-committerdate–format= '% (committerdate:short)% (refname:short) [% (Committername)]] '

ls = log--pretty=format:\ "%c (yellow)%h%c (blue)%ad%c (red)%d%c (reset)%s (green) [%cn]\"--decorate
--date=short hist = Log--pretty=format:\ "%c (yellow)%h%c (red)%d%c (reset)%s%c (green) [%an]%c (blue)%ad\"--topo-order--graph--date =short
type = cat-file-t
dump = cat-file-p

Copy Code
In this way, you can also use these shorthand commands. Let's move on.

about configuring Git shorthand commands, reference links: https://www.cnblogs.com/hutaoer/archive/2013/05/07/git_checkout.html

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.