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