Posted onEdited onInTipsViews: Waline: Word count in article: 7.3kReading time ≈7 mins.
This is an automatically translated post by LLM. The original post is in Chinese.
If you find any translation errors, please leave a comment to help me
improve the translation. Thanks!
# Create a Git code repository in the current directory $ git init
# Create a directory and initialize it as a Git code repository $ git init [project-name]
# Download a project and its entire code history $ git clone [url]
Configuration
Git's configuration file is .gitconfig, which can be in
the user's home directory (global configuration) or in the project
directory (project configuration).
1 2 3 4 5 6 7 8 9
# Show the current Git configuration $ git config --list
# Restore the specified file in the staging area to the working directory $ git checkout [file]
# Restore the specified file of a certain commit to the staging area and working directory $ git checkout [commit] [file]
# Restore all files in the staging area to the working directory $ git checkout .
# Reset the specified file in the staging area to the state of the previous commit, but keep the working directory unchanged $ git reset [file]
# Reset the staging area and working directory to the state of the previous commit $ git reset --hard
# Reset the pointer of the current branch to the specified commit, and reset the staging area, but keep the working directory unchanged $ git reset [commit]
# Reset the HEAD of the current branch to the specified commit, and reset the staging area and working directory to the state of the specified commit $ git reset --hard [commit]
# Reset the HEAD of the current branch to the specified commit, but keep the staging area and working directory unchanged $ git reset --keep [commit]
# Create a new commit to undo the specified commit # All changes made by the latter will be cancelled out by the former and applied to the current branch $ git revert [commit]
# Temporarily remove uncommitted changes and move them back later $ git stash $ git stash pop
Others
Merge the code of the development branch into master
1 2 3 4 5
$ git checkout dev #Switch to the dev development branch $ git pull $ git checkout master $ git merge dev #Merge the dev branch into master $ git push origin master #Push the code to master
Synchronize the code of master to the development branch. Merge
method: ensure that the main commit line is clean (can be safely rolled
back)
1 2 3 4 5
$ git checkout dev #Switch to the dev development branch $ git pull $ git checkout master $ git merge dev #Merge the dev branch into master $ git push origin master #Push the code to master
Generate a compressible package for release
1 2
# Generate a compressible package for release $ git archive