本文最后更新于 1842 天前,其中的信息可能已经有所发展或是发生改变。
git使用方法,主要来源于廖雪峰的教程,主要做个记录,平时自己用的时候也总是忘记一些操作,特别是发生冲突的时候。。
工作区和暂存区
git 主要分为了工作区,暂存区(stage)和版本库
通过 git add
将工作区内容移到暂存区
通过 git commit
将暂存区内容移到版本库
时光穿梭机
关键指令:
git reflog
:记录每一次命令git reset --hard HEAD^
:回退版本,可以用HEAD~100
回退到100个版本以前
文件比较
git diff
:
- 不加参数表示工作区域和快照的比较
- --cached 表示暂存区和上一次提交之间的区别
- HEAD 表示工作区和上一次提交之间的区别
撤销修改
关键命令:
git checkout -- file
:如果已经添加到暂存区,就恢复到暂存区的状态,如果没有,就恢复到版本库的状态git reset HEAD <file>
:可以撤销暂存区的修改git rm
:删除版本库里的文件
分支管理
git switch -c branch
:创建并切换分支git switch -c dev origin/dev
:切换分支到远程的dev分支git merge branch
:合并指定分支到当前分支git merge --no-ff -m
:不使用快速模式git branch -d xxx
:删除分支(已合并)git branch -D <name>
:强制删除一个未被合并的分支git cherry-pick commit
:把 commit 复制到当前分支git push -u origin dev
:将本地创建的分支提交到远程,创建关联(只要第一次使用就像,第二次就直接push就行)git push origin --delete dev
:删除远程分支
工作区暂存
git stash
:保存工作区git stash list
:查看保存的内容git stash pop
:弹出并删除stash内容
标签
git tag <name> (commit id)
:打标签,不输入 commit id 就是最新提交git tag -d v0.9
+git push origin :refs/tags/v0.9
:删除远程仓库的tag
速查表
https://gitee.com/liaoxuefeng/learn-java/raw/master/teach/git-cheatsheet.pdf
Nice blog here! Also your site loads up fast! What host are
you using? Can I get your affiliate link to your host? I wish my website loaded up
as fast as yours lol
Hi I am so happy I found your blog page, I really found you by error, while I was researching on Google for something else, Regardless I am here now and would just like to say cheers for
a tremendous post and a all round exciting blog (I also love the theme/design), I don’t have time to look over it
all at the moment but I have saved it and also added in your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the awesome jo.
I’m really impressed with your writing skills as well
as with the layout on your blog. Is this a paid theme or did you modify it yourself?
Anyway keep up the excellent quality writing, it is rare to see a great blog like this one today.