Win10系统屏幕保护程序设置为灰色
915 2023-04-02 19:59:55
与原始仓库同步可以使用merge或者rebase两种不同的方法。
https://github.com/upstream/master.git
git remote add Upstream https://github.com/upstream/master.git
git commit
git remote update Upstream
git checkout master
git pull upstream master
git rebase Upstream/master
git push origin master
在使用pull,push方法同步, 或者使用rebase,push同步的过程中,也许会出现冲突(conflict)。在这种情况,需要手动解决冲突。
比如rebase发生冲突时,Git会停止rebase并会让你去解决 冲突;在解决完冲突后,用”git-add”命令去更新这些内容的索引(index), 然后,你无需执行 git-commit,只要执行:
git rebase --continue
这样git会继续应用(apply)余下的补丁。
在任何时候,你可以用–abort参数来终止rebase的行动,并且”mywork” 分支会回到rebase开始前的状态。
git rebase --abort
Git中从远程的分支获取最新的版本到本地有这样2个命令:
1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge。
git fetch upstreamgit checkout mastergit merge upstream/master
上述命令相当于首先从远程的upstream原始仓库下载最新的版本到origin/master分支上, 然后合并到本地的master分支。
2. git pull:相当于是从远程获取最新版本并merge到本地。
git pull upstream master
上述命令其实相当于git fetch 和 git merge。
在实际使用中,git fetch更安全一些,因为在merge前,我们可以查看更新情况,然后再决定是否合并。因此可以用git fetch和git merge代替git pull,具体操作可以参考git如何与原始仓库同步
关于rebase与merge的区别还挺复杂的,可以参考advance git,git-变基,git merge 和 git rebase 小结
当你进行开发的时候,原始的仓库主分支很可能会更新,你应该保持你复制的本地分支是目前最新的。此时你就可以使用 (1)git merge,即git fetch和git merge(或者git pull),(2)git rebase两种方法获取最新的原始仓库,并保持你自己的修改。