Sourcetree ahead of a version, behind n versions

Source: Internet
Author: User
Tags sourcetree

Sourcetree ahead of a version, behind n versions

In the use of Sourcetree often meet ahead of a version, backward n version of the situation, to meet this situation should do?


First open the terminal, preferably from the sourcetree inside open, the menu bar has a terminal button.

Then enter:

$ git reset--hard head^

The meaning of this sentence is to undo your most recent commit and return to the state before push. But the contents of all commits are gone . It is very not recommended to use this parameter and will sacrifice too much code.

If you do not want commit to disappear, you can change the parameters. Use this parameter to ensure that the code you submit is kept intact. The premise is that your local workbench is clean . Save all the code.

$ git reset--soft head^


After executing this sentence, pull the code back again, and the push will be withdrawn.


If you want to rewind multiple push at once, you can: (example is undo last three commits)

$ git reset--soft head~3


If you want to fallback to a specific version, enter it in the terminal:

$ git reset--soft 1234567

1234567 is the version number to be rolled back to, depending on the situation, here is just an example.


The version number can not write the whole, the first few can be, git will automatically go to find. Of course, you can't just write the top one or two bits, because git might find multiple version numbers, and there's no way to determine which one.


Finally, summarize:

  • HEADThe point is the current version, so git allows us to navigate between versions of history, using commands git reset --hard commit_id .

  • Before you travel, git log you can view the commit history to determine which version to fallback to.

  • To return to the future, use the git reflog view command history to determine which version to return to in the future.


Sourcetree ahead of a version, behind n versions

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.