首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从本地存储库恢复原始源

如何从本地存储库恢复原始源
EN

Stack Overflow用户
提问于 2017-02-25 10:44:27
回答 3查看 874关注 0票数 2

git中最好的一个,它是分布式的。比方说,我们正在进行一个项目,所有最新的分支都会被提取并合并到我的本地存储库中。

然后服务器崩溃,没有备份,没有镜像,等等。所以中央存储库已经丢失了。

是否有可能从我的本地存储库中用所有分支恢复中央存储库?

类似于服务器上的git init --bare --shared=group ./repo.git,然后是git please --recover --with=allbraches mylocal.repository to ssh://...

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-02-25 11:02:47

你的本地回购公司,git push origin --all。我假设还原服务器上的新回购具有相同的URL。如果URL已经更改,那么首先执行git remote set-url origin <new URL>

票数 3
EN

Stack Overflow用户

发布于 2017-02-25 11:26:14

执行以下命令

代码语言:javascript
运行
复制
# Check remote Git server.
git remote -v

# If Git server changed or doesn't exist.
git remote set-url origin your_remote_git_server

# For example.
git remote set-url origin https://github.com/donhuvy/elasticsearch.git

# Check your permission on Git server. You must be master user.
# Force push all branches to remote Git server.
git push origin --all --force

# Force push all tags to remote Git server.
git push origin --tags --force

# Check result after the above steps by few command.
git status
git branch --all
git log --oneline -10
git log --oneline --graph --decorate --all
票数 2
EN

Stack Overflow用户

发布于 2017-02-25 11:11:09

由于您的遥控器已被移除,所以您还没有任何来源,因此您必须在服务器上创建一个新的回购程序,而不是更新您的远程url以指向新的

如果你不想要当地的分支机构,只需按下你所需要的。

这里有一张纸条,我用它来签出所有的分支,而不是把它们推到新的遥控器上。

代码语言:javascript
运行
复制
#!/bin/bash

# update the new origin 
# (or leave the same one if its the same as the original)

git remote set-url origin <new-url> 
# loop over all the original branches
# 1. check them out as local branches 
# 2. set the origin as the track branch
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
    git branch --track ${branch#remotes/origin/} $branch
done

# now push all branches and tags
git push origin --all    
git push origin --tags

剧本是做什么的?

git branch -a

获取所有本地分支的列表。

| grep remotes分支名称是:' remotes /origin/‘,因此这将从分支名称中移除远程

| grep -v HEAD | grep -v master

删除主(当前分支)和HEAD,这是最新提交的别名

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42455167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档