Git - 推动提交到不同的分支 [英] Git - Moving Pushed Commits to a Different Branch

查看:152
本文介绍了Git - 推动提交到不同的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的老板最近决定试试一个外包集团为了增加产能,因为我们修改了现有的应用程序以添加新功能。尽管我担心他选择的团队似乎沟通不好,并没有提出足够的问题来真正理解并且很有效,但是我们仍然和他们一起去。

我们将它们设置为在我们的Git存储库上进行协作(托管在GitHub上)。我们为他们创建了一个分支(TheOutsourcedBranch,我们会调用它),并要求他们在分支中完成他们所有的工作。

另外,我们问他们在每天结束时推送他们的提交,以便我们能够获得他们的工作速度和(更重要的)他们的代码有多好的一个体面的想法。

今天他们第一次推。五个提交,他们全都在掌握。我试图弄清楚如何将他们的提交从主人转移到TheOutsourcedBranch,而不会失去他们所做的工作(尽管从外观上看,我们将不得不抛弃它)。





橙色点是他们的提交,灰色点是我的。



我知道有几十个问题重新定义(这可能是我需要在这里做的),但我很难弄清楚哪些适用于我的具体情况。如果真的有问题,外包集团和我自己是目前唯一真正使用回购协议的人。



预先感谢!






编辑:
我可能找到了我想要的:使用Git将最近的提交移动到新分支



不过,我想检查我的理解。在本地,我创建了一个分支(TheOutsourcedBranch),它将包含所有的A-H。然后我重新将主人重新设置为C.主人现在将包含A-C。



假设这是正确的,那对我(本地)会很好。但是,我需要做些什么来强制远程存储库(GitHub)接受我的本地视图,看看事情是如何实现的并放弃其历史版本?

一旦完成了这个问题,我想我可以重新处理这个问题,使它更通用/提供信息,并删除一些绒毛 - 否则它可能是一个很好的删除候选对象,我猜。

$ b

  git分支他们的分支

解决方案

-branch master
git reset --hard master $ SHA1_OF_C
git push --force $ SHARED_REPO_REMOTE

这将重写历史;它会创建一个等价于当前主分支名为他们的分支的新分支,然后重置您的本地主分支以指向随机的SHA1(...或分支,或标签或其他),并最终强制更新远程存储库分支以匹配您的本地分支。



这恰好符合您所需的情况。

注意事项:这会重写历史记录,并且可能会造成任何人破坏了旧的主人。注意以下合并问题。



不需要重新分期。

(另外,我建议你可以给他们一个临时存储库,或者让他们使用 git send-email ,或者使用GitHub拉取请求,否则阻止他们推送到主服务器,直到他们正确。根据你的总结,可能会有一段时间。)


My boss decided recently to try out an outsourcing group "for increased capacity" as we modify an existing application to add new features. Despite my concern that the group he chose didn't seem to communicate well and wasn't asking enough questions to truly understand and be effective, we went with them anyway.

We set them up to collaborate on our Git repository (hosted on GitHub). We created a branch just for them (TheOutsourcedBranch, we'll call it) and requested that they to do all of their work within this branch.

Additionally, we asked that they push their commits at the end of each day so that we can get a decent idea of how fast they work and (more importantly) how good their code is.

Today they pushed for the first time. Five commits, all of them in master. I'm trying to figure out how to move their commits from master into TheOutsourcedBranch, without losing the work they've done (although from the looks of it, we're going to have to throw it away anyway).

Orange dots are their commits, gray dots are mine.

I know there are a zillion questions about rebasing (and that might be what I need to do here) but I'm having a hard time figuring out which of them apply to my specific case. And in case it matters, the outsourcing group and myself are the only people that are really using the repo right now.

Thanks in advance!


Edit: I may have found what I'm looking for: Move the most recent commit(s) to a new branch with Git

I'd like to check my understanding, though. Locally, I create a branch off of master (TheOutsourcedBranch), which would contain everything A-H. Then I reset master back to C. Master would now contain A-C.

Assuming that is correct, that would be fine for me (locally). But then what do I need to do to "force" the remote repository (GitHub) to accept my local view of how things played out and discard its version of the history?

Once this has played out I think I can re-work this question to make it more generic/informative and cut out some fluff--otherwise it's probably a good candidate for deletion, I would guess.

解决方案

Getting the branch is easy:

git branch their-branch master
git reset --hard master $SHA1_OF_C
git push --force $SHARED_REPO_REMOTE

This will rewrite history; it creates a new branch that is equivalent to the current master branch named their-branch, then resets your local master to point to a random SHA1 (...or branch, or tag, or whatever), and finally forcibly updates the remote repository branch to match your local branch.

That delivers exactly the situation you want.

Caveats: this will rewrite history, and can screw up anyone who has built off the old master. Watch out for merge problems following.

No rebasing desired or required.

(As an aside, I suggest you either give them a staging repository, or get them to use git send-email, or use GitHub pull requests, or otherwise prevent them pushing to master until they get it right. Which, based on your summary, might be some time away.)

这篇关于Git - 推动提交到不同的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆