首页·终端命令

git pull

git

用法

git pull [--rebase|--ff-only] [<remote> <branch>]

把 fetch 和 merge 一次做完,这正是那些意外合并提交的来源;用 --rebase 或 --ff-only 可以避免。

常用选项

选项含义
--rebasereplay your commits on top instead of merging
--ff-onlyrefuse if a merge commit would be needed
--no-rebasemerge, whatever pull.rebase says
--autostashpark local changes for the duration
--prunedrop tracking refs for deleted branches
--depth <n>shallow pull

示例

git pull --rebase origin main

brings in server commits and puts yours on top

git pull --ff-only

updates only when nothing has to be merged

git pull --autostash

pulls even with uncommitted changes in the way

难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. git pull 是做什么的?

把 fetch 和 merge 一次做完,这正是那些意外合并提交的来源;用 --rebase 或 --ff-only 可以避免。

Q. 怎么写?

git pull [--rebase|--ff-only] [<remote> <branch>] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 6 个,完整列表在 man git。这条命令属于git。

相关命令

man 手册: man git-pull