[关闭]
@JunQiu 2018-09-18T13:22:25.000000Z 字数 1700 阅读 1307

git : stash、rebase、pull、fetch

summary_2018/08 git


1、日常工作

1.1、git:stash、rebase、pull、fetch

2、技术学习

2.1 git stash:将工作临时存储
  1. $ git status
  2. # On branch master
  3. # Changes to be committed:
  4. # (use "git reset HEAD <file>..." to unstage)
  5. #
  6. # modified: index.html
  7. #
  8. # Changes not staged for commit:
  9. # (use "git add <file>..." to update what will be committed)
  10. #
  11. # modified: lib/simplegit.rb
  12. // 存储工作区和暂存区的修改
  13. $ git status
  14. # On branch master
  15. nothing to commit, working directory clean
  16. // 查看stash:git stash list
  17. // 恢复stash、压栈式,数字最小的最近
  18. git stash apply //最近
  19. git stash apply stash@{2}
  20. Tips:若与stash后的commit有冲突,会提示并保存两者
  21. // 暂存区文件被放回工作区(???但是我测试好像并不会,你们可以试试。。)
  22. git stash apply命令时带上一个--index的选项来告诉命令重新应用被暂存的变更。
  23. // 删除stash
  24. 运行 git stash drop,加上移除的储藏的名字
  25. git stash pop来重新应用储藏,同时立刻将其从堆栈中移走。
  26. Tips:如果开发的时候发现bug,需要先修改bug,可以stash一下,虽然也可以另开分支,但是对于接下来开发任务不利(若bug与接下来的任务有关),stash可以提前更正,以免做无用功。

2.2 git rebase
  1. // 如下
  2. $ git checkout mywork
  3. // 把你的"mywork"分支里的每个提交(commit)取消掉,并且把它们临时保存为补丁(patch)(这些补丁放到".git/rebase"目录中),然后把"mywork"分支更新到最新的"origin"分支,最后把保存的这些补丁应用到"mywork"分支上。
  4. $ git rebase origin
  5. // 冲突解决
  6. 这种情况,Git会停止rebase并会让你去解决冲突;在解决完冲突后,用"git-add"命令去更新这些内容的索引(index),然后,你无需执行 git-commit,只要执行:
  7. $ git rebase --continue
  8. // --abort参数来终止rebase的行动,并且"mywork"分支会回到rebase开始前的状态。
  9. $ git rebase --abort

2.3 git pull与git fetch
  1. // 默认情况下,git fetch取回所有分支(branch)的更新。如果只想取回特定分支的更新,可以指定分支名。(并记录到.git/FETCH_HEAD文件中 )
  2. git fetch <远程主机名> <分支名>
  3. // 拉取某个分支并在本地建立对应的分支
  4. git fetch <远程主机名> <分支名>:local branch
  5. // 比较
  6. git diff local branch
  7. // merge
  8. git merge local branch
  9. // 删除分支
  10. git branch -d local branch
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注