Git Learning Note

- Files in the index: Tracked files
- Files not in the index: Untracked files
- The working tree is the working directory.
- As long as the content of the files in the index is consistent with the content of the files in the working directory, it is called a “Stage” state.
- As long as the content of the files in the index is inconsistent with the content of the files in the working directory, it is called an “Unstage” state.
Git Commands
Command: git
m
= messageinit
= initializeadd
= add to the GIT indexrm
= removestatus
= check current status
git diff
Show differences
HEAD
= compare changes with the latest changes-cached
= compare changes in the index with the latest changes in the local repository--binary
= compare binary file differences--name-only
= compare files in the working directory, list file names--name-status
= list how many files have been changed between the working directory and the index
git diff 'src-commit' 'tgt-commit'
compare differences between commitsgit diff 'commit'
compare differences with the target commit
git reset
Reset the index
-p
= select which changes in the index to removeHEAD
= reset the index and branch (add ~1 to revert to the previous version, and so on)--mixed
= reset HEAD and index (default)--hard
= reset HEAD, index, and working directory--hard
ORIG_HEAD = revert to the previous version (always revert to the version before the reset)
git revert
Revert to a previous version by making an opposite commit
-h
= help, list functions--abort
= cancel--continue
= continue--quit
= stop
git clone
Download a remote repository
git clone --no-checkout 'URL' 'Filename'
will use the filename and not checkoutgit clone --bare 'url'
download the repository itself
git log
View logs
--oneline
= short log version--oneline
–graph = log version + graph, can add “-number” to show the number of entriesgit log --oneline --graph --all -10
get 10 entries of all history data
git reflog
Record every version control record under the working directory
git checkout
Check out/retrieve
-- 'name'
= copy the content of the name file from the index back to the working directory--orphan
= create a new branch without parentscheckout -b "Filename"
can create a new branch and switch to it
git switch
Switch branches
git clean
Clean the working directory
-f
= force delete-d
= delete the entire working directory-x
= perform clean task, ignoring .gitignore settings-n
= see which files will be cleaned
git stash
Stash changes in the working directory
save 'message'
= stashpop
= retrieve stash
git branch
View/create branches
-d
= delete branch (can only delete merged branches)-D
= force delete branch-r
= list all remote tracking branches-a
= list all remote + local branchesgit branch --merged
list all merged branchesgit branch --no-merged
list all unmerged branchesgit branch --merged | egrep -v "(^\*|master|develop)" | xargs git branch -d
delete all merged branches (not available in CMD/Powershell)
git merge
Merge branches
--ff
= fast-forward merge (default)--no-ff
= non-fast-forward merge--ff-only
= fast-forward merge only--no-commit
= merge without committing--abort
= abort merge--squash
= squash and merge (cannot be used with disabling fast-forward, and no merge graph will appear)git merge --no-ff --no-commit 'branchName'
merge without committing
git rebase 'commit_id'
Rebase
-i
--continue
= continue--skip
= skip--abort
= cancel
git cherry-pick
Forward pick and merge
--continue
= continue--quit
= stop--abort
= cancel
git push
Push to remote
--all
= push all branchesgit push -u origin master
link the local branch (master) with the remote branch (origin)git push origin --delete
‘branchName’ delete remote branch (must delete locally first)
git fetch
Download changes from the remote repository
--prune
prune deleted remote branches
git pull
Pull from the remote repository
pull
= git fetch + git mergegit pull --rebase
= git fetch + git rebase
git remote
Remote
-v
= list URLs-h
= remote helpset-url
= change URLgit remote set-url origin 'new url'
change the old URL to the new URL
git commit
Create a version
git apply
Apply a version (commit)
--check
= check files--reverse
= revert (short -R)
git config
GIT settings
Add
--global
to set globally
core.quotepath
= set to false to display Chinesecore.editor
= view current editorgit can only display ASCII characters
set LC_ALL=C.UTF-8
: To display Chinese in environments other than git bash
- Change environment variable (permanently save) >
setx LC_ALL C.UTF-8
- MAC/Linux >
export LC_ALL=C.UTF-8
Conflict Issues
Display message:
- content = content conflict
It is recommended to merge manually