git 流程
Workspace 工作区
Index / Stage 暂存区
Repository 本地仓库区
Remote 远程仓库区
git 常用命令
add 将改动由工作区添加到暂存区
git add .
git add -A
git add -u
git add fileName/dirName
git add fileName1 fileName2 ..
git rm fileName
git rm --cached fileName
git mv oldFileName newFileName
status 查看工作区和暂存区的状态
git status
commit 将改动由暂存区提交至本地仓库区
git commit -m msg
git commit --amend -m msg
git commit --amend --no-edit
git commit -am msg
git commit -n(--no-verify简写)
remote 远程仓库
git remote
git remote -v
git remote add origin(远程主机名) url
git remote -rm origin
pull 拉取远程仓库最新代码
git pull
git pull origin(远程主机名) branchName
push 推送本地仓库至远程仓库(相对于当前分支)
git push
git push origin 本地分支:远程分支(本地分支和冒号可以省略)
git push origin branchName
git push -u origin brancName
git push origin --delete branchName
git push origin :brancName(等同于推送一个空的本地分支到远程分支)
git push -f(--force简写) origin
git push origin HEAD --force
git push origin <tagname>
git push origin --tags
git push origin :refs/tags/tagName
branch 分支
git branch branchName
git branch -r
git branch -l(可以省略)
git branch -a
git branch -av
git branch -vv
git branch -d branchName
git branch -D branchName
git branch -m newBranchName
merge
merge有三种合并方式
git merge branchName
git merge --no-ff branchName
git merge --squash branchName
stash 内存(在你当前分支工作区暂存区有修改时,你并不想提交到本地仓库区,又需要去修改其他分支的bug时,可以先存进内存在切换分支,修改完毕在切回来,从内存中恢复)
git stash
git stash pop
git stash save msg
git stash -u
git stash show
git stash show -p
多个stash 需要在命令结尾加上 @stash{index} index默认从0开始,不加默认为0
git stash list
git stash clear
git stash show @stash{index}
git stash show -p @stash{index}
git stash pop @stash{index}
git stash apply @stash{index}
git stash drop @stash{index}
checkout 用与切换/新建分支,回退本地仓库版本,回退工作区/暂存区内容
git checkout branchName
git checkout -b branchName
git checkout -b branchName origin(远程主机名)/remoteBranchName
git checkout .
git checkout fileName
reset 回退到某个commitId,丢弃之前所有的提交
git reset --hard commitId
git reset fileName
git reset
git reset HEAD (默认)
git reset --hard
git reset --hard HEAD^
git reset commitId
git reset --mixed commitId
git reset --soft commitId
git reset --hard commitId
revert 撤销某次提交并生成一条新的提交记录(手动commit/自动commit)
git revert HEAD
git revert HEAD^
git revert HEAD^^
git revert HEAD~num
git revert commitId
git revert commitId --no-edit
cherry-pick 就是将指定的提交commitId应用于其他分支,在当前分支可以用于恢复被reset/revert掉的提交
git cherry-pick commitId
diff
git diff --check
tag 打个版本标签
git tag tagName
git tag tagName commitId
git tag -a tagName -m msg commitId
git show tagName
git tag -d tagName