-
Notifications
You must be signed in to change notification settings - Fork 0
Git
Seele edited this page May 9, 2018
·
3 revisions
- 提交文件
git add file 添加文件到暂存区
git commit -m '' 提交文件到仓库
- 删除文件
git rm file
- 撤销修改
git checkout --file 丢弃工作区的修改
git reset HEAD file 把暂存区的修改撤销掉,重新放回工作区
- 版本退回
git reset --hard HEAD^ ^代表上个版本 ^^上上个版本 以此类推
git reset --hard [commit id]
- 查看日志
git log
git log --pretty=online 简洁版
git reflog 可以查看历史命令,用来确认退回到哪一个版本
- 查看当前状态
git status
- 查看修改内容
git diff
- 关联本地仓库到远程仓库
git remote add origin [https or git protocol]
- 把本地库内容推送到远程库
git push -u origin [master] master 是本地分支
- 克隆一个本地库
git clone [https or git protocol]
- 拉取
git pull
- 创建与合并分支
git branch 查看分支
git branch [name] 创建分支
git checkout [name] 切换分支
以上两条可以简写 :
git checkout -b [name]
git merge [name] 合并某分支到当前分支
git branch -d [name] 删除分支
git branch -D [name] 强行删除
- 分支管理策略
git merge --no-ff -m "merge with no-ff" [name] 可以保留历史分支
- 修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除,当手头工作没有完成时 怎么办?
git stash 先临时保存起来
git stash list 查看保存的临时内容
git stash apply 回复工作内容
git stash drop 删除工作内容
以上两条也可以:
git stash pop
- 本地分支和远程分支的链接关系创建
git branch --set-upstream [this.name] origin/[long.name]
- 创建标签
git tag 查看所有标签
git tag [tagname] 查看标签信息
git tag [tagname] 打一个新标签
git tag [tagname] [commit id] 打一个新标签
git tag -a [tagname] -m "blablabla..." 可以指定标签信息