-
Create a version library
// Clone the remote version library
git clone <url>
// Initialize the local version library
git init
Copy the code
-
Modification and submission
// Check the status
git status
// View the changes
git diff
// Add all the changed files in the workspace to the stage area
git add .
// Add the specified file to the stage section
git add <file>
// Delete files
git rm <file>
// Commit all updated files
git commit -m "commit message"
Copy the code
-
Viewing Modification History
// View the commit history
git log
// View the submission history of the specified file
git log -p <file>
// View the submission history of the specified file in a list
git blame <file>
Copy the code
-
undo
git reset --hard HEAD
Copy the code
-
Branches and labels
// Display all local branches
git branch
// Switch to the specified branch or label
git checkout <branch/tag>
// Create a branch
git branch <new-branch>
// Delete the local branch
git branch -d <branch>
// Display all local labels
git tag
// Create a label based on the latest submission
git tag <tagname>
// Delete the label
git tag -d <tagname>
Copy the code
-
Merger and derivative
// Merge the specified branch to the current branch
git merge <branch>
// Derivatives specify the branch to the current branch
git rebase <branch>
Copy the code
-
Remote operation
// View remote repository information
git remote -v
// View the specified remote repository information
git remote show <remote>
// Add a remote version library
git remote add <remote> <url>
// Get the code from the remote library
git fetch <remote>
// Download code and fast merge
git pull <remote> <branch>
// Upload code and fast merge
git push <remote> <branch>
// Delete the remote branch or label
git push <remote> :<branch/tag-name>
// Upload all tags
git push --tags
Copy the code
-
The last
I recommend the video of Teacher Qian Xi from station B, which explains how to use Git in the form of video + illustration + case.