Git使用指南
本文最后更新于 1562 天前,其中的信息可能已经有所发展或是发生改变。

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

file

评论

  1. 4年前
    2020-8-09 20:00:59

    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

  2. 4年前
    2020-8-13 1:23:11

    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.

  3. 4年前
    2020-8-13 2:30:41

    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.

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇