title: Git 实用技巧 tags:
git init
git init -b main
git config --global init.defaultBranch main
git branch -m main
git clone http://git.example.com/someone/test.git
git clone http://git.example.com/someone/test.git test
git clone http://git.example.com/someone/test.git --depth=1 -b main
git add -a
git add -u
git add .
git commit
git commit -m "first commit"
git commit -am "first commit"
git status
git status -s
https://git-scm.com/docs/git-log{target="_blank"}
git log
git branch test
git checkout test
git checkout -b test
git checkout main
git merge test
git branch -d test-not-need
当两个分支都对同一行进行了修改,git 便会产生冲突,并标记为未合并
此时将每个文件进行修改,确认最后的内容,使用 git add 方法标记为冲突已解决
git add .\A.txt
在所有文件的冲突均已解决后,使用 commit 提交此次修改。
git merge --abort
git remote
默认应该为空
git remote add origin http://git.example.com/someone/test.git
git push origin main
git fetch --all
git fetch origin
git branch --set-upstream-to=origin/main main
git branch -u origin/main main
git push -u origin main
git pull
git pull origin main
git stash
git stash pop
git merge test
git rebase test
适合 hotfix
git cherry-pick 12d654f1d701cbf7cd9abb98ce84eeef460a24a7
git commit --amend
会同时提交暂存的文件
git checkout .\C.txt
保留文件
git reset --soft 12d654f1d701cbf7cd9abb98ce84eeef460a24a7
丢弃修改
git reset --hard 12d654f1d701cbf7cd9abb98ce84eeef460a24a7
git
git diff [file] > a.patch
git apply a.patch