琐碎合并块推git的服务器 [英] block push of trivial merge to git server

查看:174
本文介绍了琐碎合并块推git的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前阵子我要求我们的开发人员使用衍合而不是合并前​​推。消除琐碎的合并使得一个更容易跟踪犯下图。(如:gitk,git的日志)

A while back I asked our developers to use rebase instead of merge before pushing. Eliminating trivial merges makes for a much easier to follow commit graph (ie: gitk, git log).

有时候人们仍然不小心琐碎的合并,然后推。有没有人有方便或有提示写一个服务器端的挂钩阻止琐碎合并?

Sometimes folks still accidentally do trivial merges, then push. Does anyone have handy or have tips for writing a server-side hook that blocks trivial merges?

这是微不足道的合并,我的意思是没有冲突的合并。 <一href=\"http://mifos.git.sourceforge.net/git/gitweb.cgi?p=mifos/head;a=commit;h=c516520a9c37944c96162ffd85c00f68b81786a6\"相对=nofollow>下面是一个例子和<一个href=\"http://stackoverflow.com/questions/1824264/what-is-a-trivial-merge-in-git/1824297#1824297\">here's一个更好的解释在混帐一个平凡的合并。

By "trivial merge", I mean a merge without conflicts. Here's an example, and here's a better explanation of a trivial merge in git.

更新周三11月10日1时26分41秒UTC 2010 :伟大的意见,所有的!谢谢你。

Update Wed Nov 10 01:26:41 UTC 2010: great comments, all! Thank you.


  • 考虑以下几点:所有我真的要求人做的是这样的:

    • 如果混帐拉--ff只失败,请混帐拉--rebase 而不是 git的拉

    • Consider the following: all I'm really asking folks to do is this:
      • if git pull --ff-only fails, do git pull --rebase instead of git pull

      更新周四11月11日二十三点49分35秒UTC 2010

      • here's a gist with some in-progress work
      • another idea is to prevent trivial merges on the client end, with a "git push" wrapper

      更新周三12月15日十八点34分52秒UTC 2010


      • adymitruk 是接近!只是一个案件仍然没有得到解决:不平凡的合并还必须努力

      • 系统而完整的测试套件是可用的,检查出来。

      • 我要求帮助一个(的?) git的邮件列表

      • adymitruk is close! Just one case is still unresolved: non-trivial merges must still work.
      • A rather complete test suite is available, check it out.
      • I asked for help on a (the?) git mailing list.

      推荐答案

      我碰到这片code,同时试图找到一个解决方案。它不会做的正是你想要的,但它应该是宰在if语句添加额外的分支名称。

      I came across this piece of code, while trying to find a solution. It doesn't do exactly what you want, but it should be ez to add extra branch names on the if statement.

      对我的作品,至今。它迫使拉--rebase对于同一个分支,并让普通合并与其他部门去。

      Works for me, so far. it forces pull --rebase for the same branch and lets regular merges with other branches go through.

      所有学分去原作者。

      #!/bin/bash
      #
      # This git update hook will refuse unnecessary merge commits caused by pulling
      # from being pushed to a shared repository. These commits make following the
      # history of a project difficult and are always avoidable with rebasing.
      #
      # by Scott Kyle (appden)
      # modified by Olivier Refalo (orefalo)
      
      refname="$1"
      oldrev="$2"
      newrev="$3"
      
      # if this is not run as a hook, you may have messed up
      if [ -z "$GIT_DIR" -o -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
          echo "Usage: GIT_DIR=<path> $0 <ref> <oldrev> <newrev>" >&2
          exit 1
      fi
      
      # if the new revision is all 0's then it's a commit to delete a ref
      zero="0000000000000000000000000000000000000000"
      # also check if the new revision is not a commit or is not a fast forward
      # detect branch deletion, branch creation... and more
      if [ "${refname#refs/heads/}" = "master" ] || [ "$newrev" = "$zero" ] || [ "$oldrev" = "$zero" ] || [ $(git cat-file -t $newrev) != "co
      mmit" ] || [ $(git merge-base $oldrev $newrev) != "$oldrev" ]; then
          exit 0
      fi
      
      # loop through merges in the push only following first parents
      for merge in $(git rev-list --first-parent --merges $oldrev..$newrev --); do
          # lazily create the revision list of this branch prior to the push
          [ -z "$revlist" ] && revlist=$(git rev-list $oldrev)
          # check if the second parent of the merge is already in this branch
          if grep -q $(git rev-parse $merge^2) <<< "$revlist"; then
              cat >&2 <<-EOF
                  *** PUSH REJECTED ***
                  *** TRIVIAL merge detected on local branch ${refname#refs/heads/}
                  *** To fix: git rebase origin/${refname#refs/heads/}
                  ***
                  *** Next time use: git pull --rebase
                  ***
                  *** Permanent fix: git config [--global] branch.autosetuprebase always
                  *** Then for existing branches: git config branch.<name>.rebase true
              EOF
              exit 1
          fi
      done
      
      echo -Info- Clean history successfully preserved!
      exit 0
      

      这篇关于琐碎合并块推git的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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