-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
名词解释
workspace 工作区,维护当前的更改状态
staging area 暂存区,存放临时更改(git add),也称索引Index
local repository 本地仓库
remote repository 远程仓库
HEAD 当前分支最近一次commit的内容
图示
git remote
查看远端仓库信息
查看所有上游仓库名字和git地址:
git remote -v
替换已有的上游分支的url:
git remote set-url <url>
git checkout
用于检出、切换分支
git checkout master 切换到master分支
git checkout -b dev 创建并切换到dev分支
git branch
用于git 分支管理
git branch 查看本地分支
git branch -a 查看所有分支(包括本地和远端分支)
git branch dev 创建dev分支
git branch -d dev 删除dev 分支
git add、git commit 、 git push、git pull
git提交基本命令,将本地更新同步到远端分支
git add -A 添加所有更改(包括增加、修改和删除)
git commit -m "commit msg" 提交并编辑提交信息
git pull --rebase 同步远端更新
git push origin [branch name] 推送
git stash
储藏更改:将当前更改的代码储藏起来,等以后恢复使用
git stash 储藏更改到stash栈里
git stash list 查看储藏栈情况
git stash apply stash@{0} 恢复stash里id为0的更改
git stash pop 恢复的同时把stash栈里的第一项内容删掉
git stash pop VS git stash apply
原来git stash pop stash@{id}命令会在执行后将对应的stash id 从stash list里删除,
而 git stash apply stash@{id} 命令则会继续保存stash id。
git reset
清空提交区内容;本地分支回退版本
本地分支回退版本
git reflog 查看以往版本号
git reset --hard 【版本号commit id】
如果要使远端分支也会退,则继续使用
git push -f
强制推送,否则本地分支落后远程分支,无法push
git rebase
git rebase,顾名思义,就是重新定义(re)起点(base)的作用,即重新定义分支的版本库状态。
git pull = git fetch + git merge
git pull --rebase = git fetch + git rebase
git rebase 工作流
git stash 暂存更改
git pull --rebase 更新远端代码
git stash pop
如果有冲突,手动解决冲突,并提交
git add -u
git rebase --continue
如果此时提示No rebase in progress?则表示已经没有冲突了;否则上面两步要重复多次
git commit -m “xxx”
git push origin [branch] -f
冲突常见格式
<<<<<<<
你的当前代码
=======
要合并的代码(远端其他人的代码)
>>>>>>>
Metadata
Metadata
Assignees
Labels
No labels