Git basic usage Notes

Source: Internet
Author: User

about file Status files in a general warehouse may exist in these 4 states:
1) untracked files→ File not tracked (A) 2) untracked but not change→ has been tracked, but unmodified (B) 3) Changes but not updated→ has been tracked, the file was modified, but was not added to staging area (C) 4) Changes to be committed→ has been tracked, the file has been modified, has been added to staging area, this is the next commit content (D)   Common git commands 1. Git clone (B) Description: Clone code to local (Local: The current console enters the directory)   2. Git Add (a->d) git add <filePath/folderPath> Description: Adds the specified new file to the local staging area (which can be a file or all files under a folder)
git Add. Description: Submit all new files to staging area git Add--all Description: Submit all new files staging area   3. Git reset HEAD <filePath/folderPath> (d->a) Description: Withdraw the newly added file from staging area   4. Git commit (c->d) git commit <filePath/folderPath> Description: Commits the specified file modification to the local staging area (can be a file or all files under a folder)
git commit-a Description: Commit all the modified work files to staging area git   5. Git log Description: View commit commit log (each commit will generate a unique commit_id)   6. Git reset git reset--soft commit_id Description: Restores the current workspace to the state indicated by commit_id, and the modification of the workspace code is retained (D->C) git reset--hard commit_id Description: Restores the current workspace to the state indicated by commit_id, and the modification of the workspace code is also forced back to the state before the modification (D->B)   7. Git push (d->b) git push Description: Push the changes submitted to staging area to the remote repository git push-u Origin Master Description: Clone to local after initial commit 8. Git pull (b->b) Description: Updates the remote repository to a local   9. Git diff <filePath/folderPath> Description: Compare the current file and staging area file differences (all files under a file or folder)   ten. Git status Description: Scans all changes in the current workspace, including file additions, deletions, and modifications   One . Git checkout git checkout <filePath/folderPath> description: Undo local Modifications (can be a file or all files under a folder)
git checkout-f description: Undo all local Modifications     about Conflicts Most code conflicts occur when the local code is not updated to the latest state of the remote repository, and then a pull operation is made locally, which creates a conflict if the code of the remote repository and the locally modified Code section have overlapping portions. after committing the local modification commit, the pull operation view the conflicting files as follows: between <<<<< and >>>>>>> is the conflict code, "===========" above is the local modification, "===========" Below is the latest code for remote repositories then, according to the actual situation, merge the local modifications and the remote repository modification, and then commit the operation.     about tracking settings for files if we want to change the deletion of some files in the project directory without being tracked (that is, do not go to the remote repository), especially the intermediate and target files generated by the compilation, it needs to be set in. gitignore. you can ignore a folder, or you can omit a type of file for a suffix. If the project and directory do not have the file (. Gitignore is a hidden file), you can create it manually: a text file with. Gitignore as the file name. For example:

Git basic usage Notes

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.