有git清洁历史的最佳做法是什么? [英] What are the best practices for having git clean history?

查看:69
本文介绍了有git清洁历史的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读关于git工作流程的内容,我想知道历史重写的合适性。我的工作流程和我想象中的很多其他工作流程是这样的:




  • 以Github仓库为例,我们称之为rep1

  • 创建一个分支,这将是rep2

  • git将其克隆到本地以使用,即rep3

  • 进行更改,提交to rep3

  • 一旦完成,在推出PR之前推送给rep2并要求其他人反馈



当我收到反馈意见时,似乎我想要做一些重新镶嵌和压扁,因为反馈经常是一些小问题,比如重新评论意见或本应该有所不同的事情,而且不配属于自己的意见承诺。 但是从文档来看,似乎我不应该更改rep2上的历史记录,事实上--ammend在这种情况下不起作用。我的工作流程是错误的,还是我误解了有关改变历史的警告? 只有在分支机构是公共分支机构,任何人都可以获得分支机构时,您不应该重新分配此分支机构,否则可能会损坏已经克隆此分支机构的所有其他回购机构。



如果由于某些原因,您决定 rebase public(推送分支),您必须确保所有拉入此分支的用户知道你的 rebase

您可以使用git pre-rebase 钩子来检查它是否拒绝重新绑定或显示警告或错误那种情况


Reading about git workflows, I was wondering about the appropriateness of history rewriting. My workflow, and I imagine that of many others, is this:

  • Take Github repository, let's call this rep1
  • Make a fork, that'll be rep2
  • git clone it locally to work with, that's rep3
  • Make changes, commit to rep3
  • Once I am finished, push to rep2 and ask others for feedback before making a PR

As I get feedback, it seems like I would want to do some rebasing and squashing, as often the feedback are minor things like rewording comments or things that should have been different in the first place, and don't deserve their own commit.

But from the documentation, it seems like I am not supposed to change history on rep2, and indeed things like --ammend don't work in this scenario. Is my workflow wrong, or am I misunderstanding those warnings about changing history?

解决方案

The rule about rebase is this: You should only rebase your local branches once the branch is a public branch which anyone can grab it, you should not rebase on this branch again, or you can damage all the other repo who have already cloned this branch.

If for some reason you do decide to rebase public (pushed branch) you have to make sure all the users who pulled this branch are aware of your rebase.

You can check it using git pre-rebase hook to decline the rebase or to display a warning or error in that case

这篇关于有git清洁历史的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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