Py学习  »  Git

不允许从Git中的分支进行分支

ire_and_curses • 6 年前 • 2692 次点击  

在我的工作流程中,我几乎不想从master以外的分支进行分支。有几次我在启动一个新功能时意外地做到了这一点。当我这样做的时候,它会在合并时破坏我的历史。

如果我已经在一个分支机构工作了,有什么好方法可以保护我自己不去创建一个新的分支机构呢?我知道Git分支的第二个参数

git checkout -b newbranch master

但我不确定我是否能重新培训自己,让自己一直提供它。理想情况下,当我键入 git checkout -b newbranch 或者当我试图从分支中分支时发出警告。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38006
文章 [ 2 ]  |  最新文章 6 年前
tymtam
Reply   •   1 楼
tymtam    7 年前

Will Bickford
Reply   •   2 楼
Will Bickford    7 年前

git master

#!/bin/bash
cmd=$1
opt=$2
branch=$3
parent=$4
if [[ $cmd = "checkout" ]] && [[ $opt = "-b" ]]; then
  if [ -z "$parent" ]; then
    parent="master"
  fi
  /usr/bin/git checkout -b $branch $parent
else
  /usr/bin/git "$@"
fi

chmod +x /path/to/git-wrapper.sh
alias git=/path/to/git-wrapper.sh
mkdir test
cd ./test
git init
echo "First line" >readme.md
git add readme.md
git commit -m "Initial commit"
git checkout -b test1
echo "Second line" >> readme.md
git commit -am "Second line"
git checkout -b test2
echo "Third line" >> readme.md
git commit -am "Third line"
git checkout master
git branch -a
git log
git merge test1
git merge test2

Initialized empty Git repository in ...
[master (root-commit) 11bd292] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 readme.md
Switched to a new branch 'test1'
[test1 4ace272] Second line
 1 file changed, 1 insertion(+)
Switched to a new branch 'test2'
[test2 54b7fff] Third line
 1 file changed, 1 insertion(+)
Switched to branch 'master'
* master
  test1
  test2
Updating 11bd292..4ace272
Fast-forward
 readme.md | 1 +
 1 file changed, 1 insertion(+)
Auto-merging readme.md
CONFLICT (content): Merge conflict in readme.md
Automatic merge failed; fix conflicts and then commit the result.

test1 test2