Record some of the commands in Git

Source: Internet
Author: User

Initialize a git repository, using git init commands.

Add files to the Git repository in two steps:

    • The first step, use the command git add <file> , note, can be used repeatedly, add multiple files;

    • The second step, using git commit the command, is done.

  • To keep track of the status of your workspace, use the git status command.

  • If git status you are told that a file has been modified, you git diff can view the modified content.

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

      • Scenario 1: When you mess up the contents of a file in your workspace and want to discard the workspace changes directly, use the command git checkout -- file .

        Scenario 2: When you not only changed the contents of a file in the workspace, but also added to the staging area, want to discard the changes, two steps, the first step with the command git reset HEAD file , back to Scene 1, the second step by scene 1 operation.

        Scenario 3: When an inappropriate modification to the repository has been submitted, you want to revoke this commit, refer to the version fallback section, but only if it is not pushed to the remote library.

        Command git rm to delete a file. If a file has been submitted to the repository, then you never have to worry about accidentally deleting it, but be careful that you can only recover files to the latest version and you will lose what you modified after the last commit .

        To associate a remote library, use the command git remote add origin [email protected]:path/repo-name.git ;

        Once associated, use the command to git push -u origin master push all the contents of the master branch for the first time;

        Thereafter, after each local submission, whenever necessary, you can use the command to git push origin master push the latest changes;

Record some of the commands in Git

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.