Common git commands

Source: Internet
Author: User

1. Tracking new files: git add <file>  2. Staged modified file: git add <file>  3. Ignore some files: new file to ignore in. gitignore file  4. Differences between the current file and the staging area snapshot in the working directory: git diff  5. The difference between a file that has been staged and a snapshot from the last commit: git diff--cached  6. Submit Update: git commit-m "message"  7. Skip using staging area to submit updates: git commit-a-M "Message"  8. Remove Files:
    • Remove files from working directory:rm <file> git rm <file>
    • Delete from the Git repository but remain in the working directory (only removed from the tracking manifest):git rm--cached <file>
 9. Moving files: git mv <file_from> <file_to>
equivalent to: MV README. TXT README git rm README. TXT git add README  10. View commit history: git log/git log-p -2 (-p: Show differences per Commit-2: Show the last 2 updates)  11. Undo the Operation:
    • Modify the last commit:git commit--amend(This command will be submitted using the current staging area snapshot.) If you just run this command without making any changes to the submission, you will have the opportunity to re-edit the submission instructions, but the snapshot of the file to be submitted is the same as before. )
    • Cancel a file that has been staged:git reset HEAD <file>
    • Undo file Modification:git checkout-<file> (This command is dangerous, all previous changes to the file are gone)
 12. View the current remote repository: git remote-v  13. Add Remote repository: git remote add < remote repository name > <URL>  14. Fetching data from a remote repository: git fetch <remote-name>  15. Differentiate a new local branch based on the remote branch and switch to the current branch: git checkout-b < branch name > origin/< Branch name >  

To modify information about an author:

git config--global user.name "Your name"

git config--global user.email [email protected]

If the identity used for this commit are wrong, you can fix it with:

git commit--amend--author= ' Your Name <[email protected]> '

Common git commands

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.