常规使用git rebase将分支同步到master [英] Routinely sync a branch to master using git rebase

查看:825
本文介绍了常规使用git rebase将分支同步到master的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Git仓库,其分支几乎从未改变过(没有其他人正在为它做出贡献)。它基本上是一些代码和文件被剥离出来的主分支。有了这个分支可以让我轻松地打包精简版的项目,而不必每次都手动去除代码和文件。



我一直在使用 git rebase 使这个分支与主控者保持同步,但当我试图在重新绑定之后推送分支时,我总是得到这个警告:

 为防止您丢失历史记录,拒绝非快进更新
在再次推送前合并远程更改。有关详细信息,请参阅'git push --help'的'关于
快速转发的注意事项'部分。

然后使用 git push --force 它的工作原理,但我觉得这可能是不好的做法。我想让这个分支快速而轻松地与主人保持同步。有没有更好的方法来处理这个任务?



更新



请参阅此主题以获取完整说明和解决方案:

git rebase和git push:非快速转发,为什么要使用?

解决方案

诀窍是:


  • 当您重新绑定模板分支时,您将更改其历史记录(不同的SHA1),这意味着任何推送都不会是快进的(没有新的SHA1 来添加,而是一组全新的SHA1来替换)

  • 然后将该分支推送到
$ b
$ b

这是一个不好的做法:如果其他人依赖提取该分支(这不是这里的案例)如果您依赖作品的内容,则

  • (因为该内容如果设置为表示模板分支,可能与您刚刚推送的实际模板分支不同步)



  • 如果这两点不是问题,那么您可以继续。

    但是(或更多)适当的方式来处理这个问题将是有一个中间裸仓库(在远程服务器上)推送,然后从该裸仓库获取/拉取模板分支到其他需要该模板项目的服务器。


    I have a Git repository with a branch that hardly ever changes (nobody else is contributing to it). It is basically the master branch with some code and files stripped out. Having this branch around makes it easy for me to package up a leaner version of my project without having to strip out the code and files manually every time.

    I have been using git rebase to keep this branch up to date with the master but I always get this warning when I try to push the branch after rebasing:

    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes before pushing again.  See the 'Note about
    fast-forwards' section of 'git push --help' for details.
    

    I then use git push --force and it works but I feel like this is probably bad practice. I want to keep this branch "in sync" with the master quickly and easily. Is there a better way of handling this task?

    Update

    See this topic for a full explanation and solution:

    git rebase and git push: non-fast forward, why use?

    解决方案

    The trick is:

    • when you rebase your "template" branch, you change its history (different SHA1), meaning any push won't be a fast-forward one (there a no "new SHA1" to add, but an entirely new set of SHA1 to replace)
    • you then push that branch to a non-bare repo (which is now by default prevented)

    It is a bad practice:

    • if other people depend on fetching that branch (which is not the case here)
    • if you depend on the content of the working tree of the remote repo to which you push to (because that content, if set to represent the template branch, could be not in sync with the actual template branch you just pushed)

    If those two points are not an issue, you could go on.
    But the (or a more) "proper" way to deal with that would be to have an intermediate bare repo (on the remote server) to push to, and then fetching/pulling the template branch from that bare repo to other server where you need that template project.

    这篇关于常规使用git rebase将分支同步到master的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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