Please enable JavaScript.
Coggle requires JavaScript to display documents.
Git (常用指令 (Tag (git tag, 顯示 tag 清單, git tag v1.0, git push origin v1.0,…
Git
常用指令
Tag
git tag, 顯示 tag 清單
git tag v1.0
git push origin v1.0
git checkout v1.0
git tag -d v2.5
git push origin :refs/tags/v2.5
分支
git merge
放棄合併: git merget --abort
在兩個 Branch 間來回切換 (git checkout -)
得知所有的 Branch 來自何處 (git branch -vv)
修改 Branch 名稱 (git branch -m neam name)
撤销提交
還原特定擋案
git checkout [hash] [filename]
原理是先找暂存区,如果该文件有暂存的版本,则恢复该版本,否则恢复上一次提交的版本。
git rm --cached [filename]
从暂存区撤销文件
不影响已经提交的内容
取消最後一次 commit
git revert HEAD
--no-commit:只抵消暂存区和工作区的文件变化,不产生新的提交
-no-edit:执行时不打开默认编辑器,直接使用 Git 自动生成的提交信息
提交在历史中彻底消失
git reset [hash]
--hard参数可以让工作区里面的文件也回到以前的状态
復原 Git Merge (git revert HEAD or git revert -m 1 <SHA>)
提交
修正最後提交
git commit --amend --no-edit
git commit --amend -m "Fixes bug #42"
git commit --amend --reuse-message HEAD
把所有的檔案加入同一個 Commit 中 (git add –A or git add .)
一行命令達成 Add 跟 Commit (git commit -a -m ‘commit message’)
問題排查
列出最後的 log
git log -1 --stat
找回那些丢弃掉的提交
git reflog
快速找出問題點所在的 Commit (git bisect)
合併任意hash異動到目前分支
git cherry-pick [hash1] [hash2] [...hashn]
只 clone 特定分支
git clone -b develop --single-branch <url>
自動更正 (git config — global help.autocorrect 1)
自動 stash (git config — global rebase.autoStash true)