Git Version Management

Source: Internet
Author: User

Scenario 1: Add Files (single, multiple, directory) to the GIT repository and submit a version snapshot.

Scenario 2: Traversing history back to the past, version fallback, fallback from the current version to a previously submitted version.

Application Scenario 3: Through history, version back more, the purpose of the time is 2000, the result was simply worn for 1900 years, no way, and from 1900 through to the "future" of 2000 years.

Scenario 1:

Suppose there is a directory work, inside three files: file1, File2, File3:

git add work/file1    # Add single file to Repository git add work/file1 work/file2 work/file3    # Add multiple files to repository git addwork/ c8/># add the entire directory to the repository git add    . " add file1 file2 file3 "    # Commit a version snapshot

Scenario 2:

Assuming that from project development to the present, there are 3 versions of snapshots submitted to the GIT repository (3 valid git commits), respectively

" First commit "  "Second commit " "Third commit"

We are currently developing on the latest version (that is, the last commit version "third commit"), assuming that there is a significant problem with the "third commit" version and that it needs to be rolled back to "a previous version" to be re-developed:

ID git log   ID  --pretty=oneline  "5c6c438396bd9db4f24d299fc68f3150ec81b2f8"  ID----hard 5c6c438396bd9db4f24d299fc68f3150ec81b2f8  ID 

Fallback version of another method: Git has a special pointer head, always point to the current version, so you can use head to represent the previous version of head^, the last version of head^^, up several versions of the head after adding a few ^, of course, write too much ^ unrealistic, So up to 100 versions can be abbreviated to HEAD~100, others can be and so on.

git reset--hard head^  --hard head^^  --hard head~  # fallback to 100 versions

When the current version (third commit) is rolled back to a version (first commit), the current version is first commit. View history submission records, only first commit and previous commit records, as if second commit version and third commit version is an illusion that has never been submitted.

Scenario 3:

In Scenario 2, the fallback to the first commit version is found to be back, and you want to go back to "future second commit version" or "future third commit version"

# versions are free to roll back through, but all git operations are recorded in order by Git, and there must be a command to view the history operation. git reflog  IDID--hard 6w59a45  # Traversal from first commit version to  "   future  --hard 8m334k2  # crosses from first commit to the future  Third Commit version

Summary: All submitted versions are faithfully documented by Git and assigned a unique commit ID, and the key to moving back and forth between versions is to find the commit ID of the destination version.

Git Version Management

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.