GitLab本地远程更新已经fork的项目
Posted free-wings
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GitLab本地远程更新已经fork的项目相关的知识,希望对你有一定的参考价值。
单用IDEA无法做到,必须配合使用Git命令行才能做到,而且是先从原作者项目更新本地库,再从本地库push到自己远程fork项目,非常坑逼。
1.到项目clone的根目录右键Git Bash,先查看远程源,一般只有你自己fork项目的源,没有原作者的,需要添加远程源:
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git remote -v
origin http://172.16.175.36:180/baigang/sunfield-microframe-service.git (fetch)
origin http://172.16.175.36:180/baigang/sunfield-microframe-service.git (push)
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git remote add upstream ssh://[email protected]:4422/jiaoma/sunfield-microframe-service.git
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git remote -v
origin http://172.16.175.36:180/baigang/sunfield-microframe-service.git (fetch)
origin http://172.16.175.36:180/baigang/sunfield-microframe-service.git (push)
upstream ssh://[email protected]:4422/jiaoma/sunfield-microframe-service.git (fetch)
upstream ssh://[email protected]:4422/jiaoma/sunfield-microframe-service.git (push)
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git fetch upstream
The authenticity of host ‘[172.16.175.36]:4422 ([172.16.175.36]:4422)‘ can‘t beestablished.
ECDSA key fingerprint is SHA256:hFUMVxu5yYzhamirMDGSsvo3KbgbsVBQ3ZPTOBUIdqs.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
2.这里添加了原作者ssh协议的源,因为没有本机证书,无法连接成功,所以需要改为添加http协议源,这里本公司GitLab服务器需要带上180端口:
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git remote add upstream http://172.16.175.36:180/jiaoma/sunfield-microframe-service.git
fatal: remote upstream already exists.
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git remote remove upstream
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git remote add upstream http://172.16.175.36:180/jiaoma/sunfield-microframe-service.git
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git remote -v
origin http://172.16.175.36:180/baigang/sunfield-microframe-service.git (fetch)
origin http://172.16.175.36:180/baigang/sunfield-microframe-service.git (push)
upstream http://172.16.175.36:180/jiaoma/sunfield-microframe-service.git(fetch)
upstream http://172.16.175.36:180/jiaoma/sunfield-microframe-service.git(push)
这里需要先使用git remote remove命令移除此前错误添加的同名源(其实起别的名也可以,fetch时从正确名字的源获取即可)
3.从添加的原作者源fetch到本地仓库,合并到本地仓库:
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git fetch upstream
remote: Counting objects: 103, done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 103 (delta 24), reused 30 (delta 4)
Receiving objects: 100% (103/103), 12.50 KiB | 914.00 KiB/s, done.
Resolving deltas: 100% (24/24), completed with 6 local objects.
From http://172.16.175.36:180/jiaoma/sunfield-microframe-service
* [new branch] master -> upstream/master
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git merge upstream/master
Updating 2970d82..27ca203
Fast-forward
pom.xml | 58 ++------
.../microframe/common/config/RedisConfig.java | 52 +++++++
.../microframe/common/redis/RedisBaseTemplate.java | 139 ++++++++++++++++++
.../microframe/common/redis/RedisHashTemplate.java | 157 +++++++++++++++++++++
.../microframe/common/redis/RedisListTemplate.java | 130 +++++++++++++++++
.../microframe/common/redis/RedisSetTemplate.java | 110 +++++++++++++++
.../microframe/provider/MUsersSqlProvider.java | 29 ++--
.../com/sunfield/microframe/rest/MUsersRest.java | 82 ++++++++++-
.../sunfield/microframe/service/MUsersService.java | 73 ++++++++++
src/main/resources/application.properties | 52 ++++---
10 files changed, 804 insertions(+), 78 deletions(-)
create mode 100644 src/main/java/com/sunfield/microframe/common/config/RedisConfig.java
create mode 100644 src/main/java/com/sunfield/microframe/common/redis/RedisBaseTemplate.java
create mode 100644 src/main/java/com/sunfield/microframe/common/redis/RedisHashTemplate.java
create mode 100644 src/main/java/com/sunfield/microframe/common/redis/RedisListTemplate.java
create mode 100644 src/main/java/com/sunfield/microframe/common/redis/RedisSetTemplate.java
create mode 100644 src/main/java/com/sunfield/microframe/service/MUsersService.java
4.把更新push到自己远程fork库:
[email protected] MINGW64 /e/git_projects/sunfield-microframe-service (master)
$ git push
Enumerating objects: 119, done.
Counting objects: 100% (119/119), done.
Delta compression using up to 8 threads
Compressing objects: 100% (45/45), done.
Writing objects: 100% (103/103), 12.50 KiB | 2.50 MiB/s, done.
Total 103 (delta 24), reused 103 (delta 24)
remote: Resolving deltas: 100% (24/24), completed with 6 local objects.
To http://172.16.175.36:180/baigang/sunfield-microframe-service.git
2970d82..27ca203 master -> master
注意这里应push到自己的远程库,而不是原作者的!
这样成功更新了自己本地库、远程fork库,完全不需要IDEA操作了。
参考博客:
https://blog.csdn.net/define_LIN/article/details/81044421
https://www.jianshu.com/p/83be892368d8
https://blog.csdn.net/qq_38835878/article/details/81195400
https://www.zhihu.com/question/20393785/answer/30725725
https://www.cnblogs.com/dinphy/p/6409132.html
切换分支和push到fork库:
https://www.jianshu.com/p/29775d91f536
删除远程源:
https://www.cnblogs.com/BHfeimao/p/6496877.html
以上是关于GitLab本地远程更新已经fork的项目的主要内容,如果未能解决你的问题,请参考以下文章