简体   繁体   English

git-处理与原点/主节点的差异

[英]git - dealing with divergence from origin/master

On a particular project I am using git to work on a fork of a shared repo. 在一个特定的项目中,我使用git来处理共享仓库的分支。 On this fork only I (and occasionally a bot like requires.io ) have pushed commits to origin/master , so there is on concern about overwriting the work of another team member. 在此分支上,只有我(偶尔需要诸如require.io这样的机器人)已将提交推送到origin/master ,因此担心覆盖另一个团队成员的工作。

Recently, I pushed quite a few commits to a public origin/master of my fork and later, I realised some of those commits were not sensible, and wanted to edit or revert them. 最近,我将许多提交提交给了我的fork的公共origin/master ,后来,我意识到其中一些提交不明智,因此想要对其​​进行编辑或还原。 So, I took a copy of the latest version of the code on disk, reverted about 30 commits and pushed the reverted head to origin/master . 因此,我复制了磁盘上最新版本的代码,还原了约30次提交,并将还原后的磁头推到了origin/master

Then I rebased the local copy of the repo (which was now about 30 commits ahead of origin/master ). 然后,我重新构建了仓库的本地副本(现在,它比origin/master早了约30次提交)。 Now git says that my local HEAD has diverged from origin/master and have 30 and 18 different commits each. 现在git表示我的本地HEADorigin/master节点不同,并且分别有30和18个不同的提交。

I have two questions about this. 我对此有两个问题。 Obviously, I want my local commits to be pushed to origin/master , I don't want to pull --rebase and allow my local commits to be overwritten by the remote commits. 显然,我希望将本地提交推送到origin/master ,我不想pull --rebase并允许我的本地提交被远程提交覆盖。 Is there a simple way to do this without opening a merge tool frequently? 是否有一种简单的方法可以执行此操作,而无需经常打开合并工具?

Secondly, this seems very messy. 其次,这似乎很混乱。 What workflow should I be using to avoid this sort of situation? 我应该使用哪种工作流程来避免这种情况? Pushing less frequently is not likely to be a useful option here, since the buggy commits I was trying to fix were to do with a travis.ci YAML file, which I can only usefully test by pushing to origin/master . 在这里不太频繁地推送不太可能是有用的选择,因为我试图修复的bug提交与travis.ci YAML文件有关,我只能通过推送到origin/master来进行有用的测试。

Never, ever, rebase remote when there are other people pushing or pulling from it. 永远不要在其他人推挤或撤离它时为远程提供基础。 Otherwise, you're going to upset and frustrate a lot of people. 否则,您将使很多人感到沮丧和沮丧。

To do this, just don't push your commits until you're happy with them. 为此,只要在对它们满意之前就不要推送您的提交。

For reverting commits that have been pushed already, use the git revert tool to create a revert commit then push that. 要还原已经推送的提交,请使用git revert工具创建一个还原提交,然后推送该提交。

This is generally the way my workflow works. 通常这是我的工作流程的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM