Note:
Workspace: files in local directories (except hidden directories .git)
Repository: the hidden directory .git, including the temporary storage area, the first branch master, and the pointer HEA pointing to the master
-
Common git commands
Right mouse button, select GitBash
git config --glabal user.name "wcc" %Specify the user name for the warehouse% git config --glabal user.email "...qq.com" %Specify the mailbox for the warehouse% git config --list %Display current Git configuration%
git init %Create the current directory as a Git warehouse% git init [project_name] %Create a new directory [project_name], and initialize it as a warehouse%
git add test.txt %Add the file test.txt to the temporary storage area%
git commit -m "Comment" % Submit the modification to the warehouse with a comment% git commit -a %commit all changes% git commit -v % display diff information when submitting% git commit --amend %redo the last commit, if there is no change, it is used to rewrite the last commit information%
git status %Check if there are any uncommitted files%
git diff test.txt % View the modified content of the file test.txt%
git log %View file modification history%
git reset --hard HEAD^ % Roll back the files in the warehouse to the previous version% git reset --hard HEAD^^ % Roll back the files in the warehouse to the previous 2 versions, and the number of ^ represents the number of rolled back versions% git reset --hard HEAD~~100 % roll back the files in the warehouse to the last 100 versions% git reset --hard xxx % roll back the files in the warehouse to the version with version number xxx%
git reflog %View version number%
cat test.txt %View file content%
git checkout --test.txt % Abandon the modification of the file test.txt in the work area %If the modification is not placed in the temporary storage area, the modification can be successfully undone, otherwise it cannot be undone
rm test.txt %Delete the file test.txt, you can also delete the file directly in the directory %After deleting the file, commit to submit the modification % If not committed, you can checkout to restore the file git rm test.txt %delete the file and put the modification into the temporary storage area% git rm --cache test.txt %Stop tracking the file, but the file remains in the workspace%
git mv test.txt wcc.txt %Rename the file test.txt to wcc.txt, and put the modification into the temporary storage area%
git clone [URL] %Download a project and code history% git pull % update, download the code and merge it, which is equivalent to fetch + merge% git push %upload code and merge%
-
Commit message format
message |
meaning |
feat |
add new features |
fix |
fix bugs |
docs |
Documentation comments |
style |
Code format (changes that do not affect operation) |
refactor |
Refactoring, optimization (no new features, no bug fixes) |
perf |
performance optimization |
test |
increase test |
chore |
Changes to the build process or accessibility tools |
revert |
go back |
build |
Pack |
-
Resolve merge conflicts
The submitted code should be pull-commit-push
Strategy 1: Unload the entire project and pull the project again
git clone [URL]
Strategy 2: Roll back to the specified version, then pull-commit-push
①View the local historical version $ git log % Press "q" to exit the log ② After finding the version number to roll back, right click to copy ③Return $ git reset --hard xxx ④Resubmit $ git pull $ git commit $ git push
-
Pull failed
Because of a merge conflict, I and others have modified the same file
①Copy one copy of your own code, that is, copy it to a txt file
② Undo your own modification
③Re-pull to pull the code
④ Re-modify, or overwrite the new code with your own code, and selectively retain the modification after comparison.