使用 git rebase 定期将分支同步到 master
我有一个 Git 存储库,其中的分支几乎从不更改(没有其他人对其做出贡献)。它基本上是主分支,删除了一些代码和文件。有了这个分支,我可以轻松打包项目的精简版本,而不必每次都手动删除代码和文件。
我一直在使用 git rebase 来使该分支与主分支保持同步,但是当我尝试在变基后推送分支时,我总是收到此警告:
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.
然后我使用 git push --force 它有效,但我觉得这可能是不好的做法。我想快速轻松地使这个分支与主分支保持“同步”。有更好的方法来处理这项任务吗?
更新
请参阅此主题以获取完整的说明和解决方案:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诀窍是:
这是一个不好的做法:
如果这两点不是问题,您可以继续。
但是(或更)“正确”的处理方法是有一个中间裸存储库(在远程服务器上)要推送到,然后从该裸存储库获取/拉取模板分支到您所在的其他服务器需要该模板项目。
The trick is:
It is a bad practice:
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.