-
2022-05-05 21:54:42
git pull用法:
git pull命令的作用是:取回远程主机某个分支的更新,再与本地的指定分支合并。一句话总结git pull和git fetch的区别:git pull = git fetch + git merge
git fetch不会进行合并执行后需要手动执行git merge合并分支,而git pull拉取远程分之后直接与本地分支进行合并。更准确地说,git pull使用给定的参数运行git fetch,并调用git merge将检索到的分支头合并到当前分支中。
基本用法:
git pull <远程主机名> <远程分支名>:<本地分支名>
例如执行下面语句:
git pull origin master:brantest
将远程主机origin的master分支拉取过来,与本地的brantest分支合并。
后面的冒号可以省略:
git pull origin master
表示将远程origin主机的master分支拉取过来和本地的当前分支进行合并。
更多相关内容 -
IDEA中使用Git拉取代码时报 Git pull failed原因及解决方法
2020-10-14 23:48:54主要介绍了IDEA中使用Git拉取代码时报 Git pull failed原因及解决方法,本文给大家介绍的非常详细对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下 -
git-pull-request:通过命令行发送git pull请求
2021-02-03 16:25:53git-pull-request:通过命令行发送git pull请求 -
git pull
2021-01-23 15:16:43git pull的默认行为是git fetch + git merge git pull --rebase则是git fetch + git rebase. git fetch 从远程获取最新版本到本地,不会自动合并分支 1、git pull和git pull --rebase提交后分支区别 假设共同...git pull的默认行为是git fetch + git merge
git pull --rebase则是git fetch + git rebase.
git fetch 从远程获取最新版本到本地,不会自动合并分支
1、git pull和git pull --rebase提交后分支区别
假设共同基线是commit-D,从D分出了master分支和topic分支
A---B---C topic / D---E---F---G master
(1)git pull,现在master分支想merge topic分支,那么成功merge后的git提交是这样子的
A---B---C topic / \ D---E---F---G---H master
也就是之前分支记录不变,G后面多了一个提交H,H就是合并这个操作,merge层次比较明显,每个提交的时间真实,但是多个分支交叉看起来比较混乱。
(2)在master分支想rebase topic分支,那么成功merge后的git提交是这样子的
A---B---C topic / D---E---F---G---H ---A'---B'---C'master
也就是将两个分支线性的融合到一个分支,没有增加额外的提交,看起来比较清晰,但是某些修改的时间可能是虚假的(前后时间是错的)。
2、git pull和git pull --rebase提交冲突的处理方法
(1)执行 git pull 之后如果有合并冲突,使用以下三种方式处理这些冲突:
修改冲突git add ... git commit
丢掉本地提交 git reset --hard ,git pull
回到冲突前的状态 git reset --hard
(2)执行git pull --rebase之后如果有合并冲突,使用以下三种方式处理这些冲突:
git rebase --abort 会放弃合并,回到rebase操作之前的状态,之前的提交的不会丢弃;
git rebase --skip 则会将引起冲突的commits丢弃掉(慎用!!);
git rebase --continue 合并冲突,结合"git add 文件"命令一起用与修复冲突,提示开发者,一步一步地有没有解决冲突。(fix conflicts and then run “git rebase --continue”)
-
git pull 和 git pull --rebase 区别理解
2020-07-29 23:44:34git pull = git fetch + git merge git pull --rebase = git fetch + git rebase git pull 就不多说了,直接来看 git pull --rebase 吧。 现在,用户 A,用户 B 和 远程仓库的代码版本都是最新且保持一致的。 ...[root@master GitTest]# git pull warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull: git config pull.rebase false # merge (the default strategy) git config pull.rebase true # rebase git config pull.ff only # fast-forward only
git config pull.rebase false # merge (the default strategy) git pull = git fetch + git merge git config pull.rebase true # rebase git pull = git fetch + git rebase
git pull 就不多说了,直接来看 git pull --rebase 吧。
现在,用户 A,用户 B 和 远程仓库的代码版本都是最新且保持一致的。
用户 A 在本地提交了两次 commit ,领先远程仓库 2 commit:
# User A Administrator@PC-20200713AJJH MINGW64 /d/MyProject/Python/GitTest (master) $ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean Administrator@PC-20200713AJJH MINGW64 /d/MyProject/Python/GitTest (master) $ git log commit db412233fd10dbf782147ae678310ef7a412ccf4 (HEAD -> master) Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 22:28:31 2020 +0800 mv test.txt to test dir commit 32b9c4ee0b74b629e1d1e99f1d0173a831638d7c Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 22:15:01 2020 +0800 delete d.txt commit 70f19e6d0788ad7fca07b129a8615084fe08f1e9 (origin/master, origin/HEAD) Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 21:58:26 2020 +0800 modify c.txt commit 082b01177112fc3ccb93f234435fb06a930c19fb Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 21:05:16 2020 +0800 add hello world in b.txt
# User B [root@master GitTest]# git log commit 70f19e6d0788ad7fca07b129a8615084fe08f1e9 Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 21:58:26 2020 +0800 modify c.txt commit 082b01177112fc3ccb93f234435fb06a930c19fb Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 21:05:16 2020 +0800 add hello world in b.txt commit d38440866faa62ff1a2c383be1fc780bbbb859f7 Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 20:53:13 2020 +0800
然后 A 将提交 git push 到了远程仓库:
Administrator@PC-20200713AJJH MINGW64 /d/MyProject/Python/GitTest (master) $ git push Enumerating objects: 8, done. Counting objects: 100% (8/8), done. Delta compression using up to 8 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 572 bytes | 572.00 KiB/s, done. Total 6 (delta 2), reused 0 (delta 0) remote: Resolving deltas: 100% (2/2), completed with 1 local object. To github.com:2392863668/GitTest.git 70f19e6..db41223 master -> master
B 也在本地提交了一次commit:
[root@master GitTest]# vi looking.txt [root@master GitTest]# git add looking.txt [root@master GitTest]# git commit -m "add hello world in looking.txt" [master 9983c69] add hello world in looking.txt 1 file changed, 1 insertion(+) [root@master GitTest]# git log commit 9983c69644ade74a4fa0a2fa4f7bd1c1771f39a5 Author: looking <looking@qq.com> Date: Wed Jul 29 23:29:39 2020 +0800 add hello world in looking.txt commit 70f19e6d0788ad7fca07b129a8615084fe08f1e9 Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 21:58:26 2020 +0800 modify c.txt commit 082b01177112fc3ccb93f234435fb06a930c19fb Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 21:05:16 2020 +0800 add hello world in b.txt
然后 B 也准备将提交 git push 到远程仓库:
[root@master GitTest]# git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) To git@github.com:2392863668/GitTest.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:2392863668/GitTest.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
由于远程分支已经继续往前走了,所以 B 自然而然 push 失败了,而且消息也提示让先 'git pull',这时候我们的 git pull --rebase 该上场了,git pull --rebase 以后,我们查看版本日志图,发现 modify c.txt 后面的日志记录并没有像之前那样有直观的合并记录了。直接先 git pull, 再 git merge 的话则无法避免这种情况。
[root@master GitTest]# git pull --rebase remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 2), reused 6 (delta 2), pack-reused 0 Unpacking objects: 100% (6/6), done. From github.com:2392863668/GitTest 70f19e6..db41223 master -> origin/master First, rewinding head to replay your work on top of it... Applying: add hello world in looking.txt [root@master GitTest]# git log commit 3fceb8a9bdb24500a68477d4560c33cb305b5d5f Author: looking <looking@qq.com> Date: Wed Jul 29 23:29:39 2020 +0800 add hello world in looking.txt commit db412233fd10dbf782147ae678310ef7a412ccf4 Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 22:28:31 2020 +0800 mv test.txt to test dir commit 32b9c4ee0b74b629e1d1e99f1d0173a831638d7c Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 22:15:01 2020 +0800 delete d.txt commit 70f19e6d0788ad7fca07b129a8615084fe08f1e9 Author: 2392863668 <2392863668@qq.com> Date: Wed Jul 29 21:58:26 2020 +0800 [root@master GitTest]# git log --oneline --decorate --color --graph * 3fceb8a (HEAD, master) add hello world in looking.txt * db41223 (origin/master) mv test.txt to test dir * 32b9c4e delete d.txt * 70f19e6 modify c.txt * 082b011 add hello world in b.txt * d384408 mv a.txt to test directory * 648e3e1 Merge branch 'dev' to 'master' |\ | * d2009f7 (dev) add one line in c.txt by user B again | * 4505d98 add one line in b.txt by user B again * | cc12a89 add one line in a.txt by user A again |/
然后 B 再次尝试提交 git push 到远程仓库(这次 push 成功):
[root@master GitTest]# git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 233 bytes | 0 bytes/s, done. Total 2 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To git@github.com:2392863668/GitTest.git db41223..3fceb8a master -> master
如果以上直接 git pull 的话,git 会直接弹出一个类似下面这种的 merge 界面(如果有冲突的话还需要处理冲突):
Administrator@PC-20200713AJJH MINGW64 /d/MyProject/Python/GitTest (master) $ git pull remote: Enumerating objects: 2, done. remote: Counting objects: 100% (2/2), done. remote: Total 2 (delta 1), reused 2 (delta 1), pack-reused 0 Unpacking objects: 100% (2/2), done. From github.com:2392863668/GitTest db41223..3fceb8a master -> origin/master Merge made by the 'recursive' strategy. looking.txt | 1 + 1 file changed, 1 insertion(+)
而且可以看到直观的合并记录了(虽然不一定是你想要的)。
整个例子讲下来,相信你已经知道 git pull --rebase 的作用了。
-
git pull与git pull --rebase的区别
2021-10-24 09:14:23 -
关于 git pull 和 git pull origin develop 的区别
2019-09-29 17:11:14关于 git pull 和 git pull origin develop 的区别 闲来无事,正于网上冲浪之际,一位漂亮小姐姐抛来一个问题:git pull 和 git pull origin develop 有啥区别,一个答案从脑海里一闪而过——没啥区别,但好像也不对... -
git pull与git pull --rebase的区别详解
2020-03-21 11:32:30git pull = git fetch + git merge git pull --rebase = git fetch + git rebase 现在来看看git merge和git rebase的区别。假设有3次提交A,B,C。 在远程分支origin的基础上创建一个名为"mywork"的分支并提交了,... -
git pull用法
2021-11-17 09:47:33今天做了一个实验,首先假设master分支和dev分支是一样的,然后在文件夹中切换到dev分支,新增一个文件,git add, git commit, git push,然后本地切换到master分支,再pull远程的dev分支,此时dev分支多出来的文件就... -
git pull origin master与git pull --rebase origin master的区别
2021-05-26 13:08:58建议:最好看一遍廖雪峰的git教程,看完时间差不多就两个小时,git相关的知识写的很清楚,看完整个人都豁然开朗,很多git的问题都想通...所以git pull origin master与git pull --rebase origin master的区别主要是在.. -
Git教程 git pull 和 git clone的区别
2021-11-11 11:14:31使用方法 有权限的仓库 本地无代码 git pull git clone 有权限的仓库 本地有代码 git pull 无权限的仓库 本地无代码 git clone 无权限的仓库 本地有代码 删了重新下 换个说法 git pull:必须连接远程仓库才能用。... -
git pull无反应
2022-01-11 11:50:16git pull 半天没有反应 检测 $ git remote -v origin git@xxx.org:YYY/samba.git (fetch) origin git@xxx.org:YYY/samba.git (push) $ ssh -T git@xxx.org Permission denied (publickey). 处理 $ vim ~/.ssh/... -
【Git】git pull origin master与git pull --rebase origin master的区别
2020-12-03 20:11:38git pull=git fetch + git merge git pull --rebase=git fetch+git rebase git fetch : 从远程分支拉取代码,可以得到远程分支上最新的代码。 所以git pull origin master与git pull --rebase origin master的区别... -
在什么情况下,“ git pull”会有害吗?
2020-05-16 17:06:32I have a colleague who claims that git pull is harmful, and gets upset whenever someone uses it. 我有 -
git pull 出现的问题
2022-03-25 15:24:13git pull有两个时机: 1. git add . 之前 没有冲突 -> git pull 出现冲突 ->手动在电脑上复制一个副本文件出来 -> 把自己对冲突的文件撤销 ->提交步骤 2. git add . 之后 没有冲突 -> git ... -
git pull没有任何反应
2021-07-19 18:55:45Since yesterday, I have a big issue with my Professional computer : I cannot use git pull. This is really weird because every other git command's works.What I tried :Reinstalling Github for Windows, G... -
git系列之-彻底搞清楚git clone与git pull
2022-02-14 10:26:501、git clone git clone顾名思义就是将其他仓库克隆到本地,包括被clone仓库的版本变化。 举个例子,你当前目录比方说是在f:/code/中,此时若想下载远程仓库,本地无需git init,直接git clone url(url是你远程... -
git强制更新本地代码,git pull无法更新本地代码,git pull显示更新成功但是本地并没有拉去到最新的代码
2022-03-02 20:16:07git强制更新本地代码,git pull无法更新本地代码,git pull显示更新成功但是本地并没有拉去到最新的代码 -
git pull 命令
2021-01-17 14:28:16git pull 命令git pull 命令用于从远程获取代码并合并本地的版本。git pull 其实就是 git fetch 和 git merge FETCH_HEAD 的简写。命令格式如下:git pull :实例更新操作:$ git pull$ git pull origin将远程主机 ... -
同步fork的上游仓库代码更新:git pull upstream
2021-10-10 21:33:10git pull upstream同步上游更新 在使用git管理项目的时候,不管是gitlab还是github项目,都可以通过fork将上游仓库的项目复制到自己仓库中,但是上游的仓库变更时,怎么同步更新自己仓库里的变化呢? 一般有两种方式... -
Idea 中 Git pull 和 Git update 功能的区别
2022-04-08 10:20:27Idea 中 Git pull 和 Git update 功能的区别 一、如何操作 1、pull: 选中项目、某个文件 --- 右键 --- Git --- pull 2、update: 选中某个分支 --- 右键 --- update 二、理解区别点 1、远程仓库先提交 ... -
git pull命令操作 git pull <remote> <branch>
2020-08-15 11:15:49git pull命令操作 git pull <remote> <branch> git pull <remote> <branch> 解决1: git pull origin v2.0.0 git branch --set-upstream-to=origin/<branch> v2.0.0 解决2: git ... -
git pull直接覆盖
2021-05-07 10:19:02git pull直接覆盖 git pull会把本地未提交修改覆盖。 处理的方式非常简单,主要是使用git stash命令进行处理,分成以下几个步骤进行处理。 1、先将本地修改存储起来 $ git stash 这样本地的所有修改就都被暂时存储... -
git pull失败的解决方法
2021-07-20 10:03:36git pull时报错: error: Your local changes to the following files would be overwritten by merge 解决方法: 强制覆盖掉自己的本地修改(不推荐,个人修改代码未保存) git reset --hard //强制覆盖 git ... -
git pull和git pull -- rebase
2017-12-14 23:56:061 工作区不干净(没有git add .)可以git pull或者git pull - -rebase代码吗? 结果是不可以,如果你没有将修改提交到暂存区,那么无论是pull还是pull –rebase都是不可以拉下来代码的 接下来我们再多思考下: 2 ... -
(转载)git pull origin master与git pull --rebase origin master的区别
2020-07-29 17:13:40请移步原文 ... 1.git pull ...git pull = git fetch + git merge FETCH_HEAD ...git pull --rebase = git fetch + git rebase FETCH_HEAD ...所以git pull origin master与git pull --rebase orig.. -
git pull命令的用法
2021-04-14 14:52:18git pull用法: git pull命令的作用是:取回远程主机某个分支的更新,再与本地的指定分支合并。 一句话总结git pull和git fetch的区别: git pull = git fetch + git merge git fetch不会自动进行合并。执行后... -
git pull --rebase的作用是什么,它与git pull有什么区别?
2020-08-23 03:39:01在push代码时,会提示使用git pull命令,也就是拉取远端代码,更新我们的仓库,那么为什么又要加个 --rebase命令呢?下面来说说这个问题,先从这两命令开始。 git pull = git fetch + git merge FETCH_HEAD git ... -
git pull之后失败,后使用git pull --rebase origin master出现代码丢失
2020-07-22 18:58:18自己独立开发一个项目,所以代码就没有天天往git上上传,隔三岔五穿一次,在项目接近尾声的时候出现问题了。刚好前几天公司给换了一个电脑,添加密钥后再上传代码,没有上传成功,换仓库地址了,按理说我是git clone... -
git pull的时候发生冲突的解决方法
2021-08-21 16:32:39git pull的时候发生冲突的解决方法 报错提示内容: error: Your local changes to the following files would be overwritten by merge” 方法一、stash 1 git stash 2 git commit 3 git stash pop git stash: ...