我在一个名为test-hotfix的repo中进行了热修复过程的实验,该repo可以在以下地址找到:
https://github.com/oldsj/test-hotfix/commits/master。
基本上,只要从生产分支创建了热修复分支,该过程似乎相当简单,即使master比imp/prod领先也是如此。
注:我们将imp称为“预生产环境”。
master (开发分支)
git init
echo "Hello wolrd" > hello.txt
git add -A .
git commit -m "add hello.txt"
git log
commit 66b1a08080f0db548da85471b4673c5a9f6d703f (HEAD -> master)
cat hello.txt
Hello wolrd
git checkout -b imp
git checkout -b prod
产品显示错字
cat hello.txt
Hello wolrd
git log
commit 66b1a08080f0db548da85471b4673c5a9f6d703f (HEAD -> prod, master, imp)
让我们在生产环境之前向主分支添加一些提交。
git checkout master
git log
commit 66b1a08080f0db548da85471b4673c5a9f6d703f (HEAD -> master, prod, imp)
echo "new stuff" >> newstuff.txt
git add -A .
git commit -m "add newstuff.txt"
git log
commit df1ca012262c26ab3a29d81b5cb6d46f6c1fc3cc (HEAD -> master)
commit 66b1a08080f0db548da85471b4673c5a9f6d703f (prod, imp)
有用户报告在 prod 环境中发现了一个错别字,让我们通过从 prod 分支创建新分支来进行紧急修复:
git checkout prod
git log
commit 66b1a08080f0db548da85471b4673c5a9f6d703f (HEAD -> prod, imp)
git checkout -b hotfix
Switched to a new branch 'hotfix'
git log
commit 66b1a08080f0db548da85471b4673c5a9f6d703f (HEAD -> hotfix, prod, imp)
echo "Hello world" > hello.txt
git add -A .
git commit -m "fix typo"
git log
commit 1243123edc75e0abf349e1bb154d39c9f25dab2d (HEAD -> hotfix)
cat hello.txt
Hello world
很棒,我们在hotfix分支中修复了拼写错误,现在合并到主分支(master)并在开发(dev)环境中进行测试。
git checkout master
git merge hotfix
git log
commit 2672d5059a55472132f02178c7f51d8b1af0f8ea (HEAD -> master)
> cat hello.txt
Hello world
在开发环境中看起来很不错!让我们合并到重要环境和生产环境中。
git checkout imp
git merge hotfix
git log
commit 1243123edc75e0abf349e1bb154d39c9f25dab2d (HEAD -> imp, hotfix)
cat hello.txt
Hello world
git checkout prod
git merge hotfix
git log
commit 1243123edc75e0abf349e1bb154d39c9f25dab2d (HEAD -> imp, hotfix)
cat hello.txt
Hello world
git branch -D hotfix
通过将“PR”合并到这些环境分支中,在较低的环境中测试后,在生产环境中修复了错别字。现在让我们将开发更改提升(commit df1ca012262c26ab3a29d81b5cb6d46f6c1fc3cc)。
git checkout master
git log
commit 2672d5059a55472132f02178c7f51d8b1af0f8ea (HEAD -> master, imp)
commit 1243123edc75e0abf349e1bb154d39c9f25dab2d (prod)
commit df1ca012262c26ab3a29d81b5cb6d46f6c1fc3cc
commit 66b1a08080f0db548da85471b4673c5a9f6d703f
git checkout imp
git merge master
git log
commit 2672d5059a55472132f02178c7f51d8b1af0f8ea (HEAD -> imp, master)
commit 1243123edc75e0abf349e1bb154d39c9f25dab2d (prod)
commit df1ca012262c26ab3a29d81b5cb6d46f6c1fc3cc
commit 66b1a08080f0db548da85471b4673c5a9f6d703f
cat newstuff.txt
new stuff
cat hello.txt
Hello world
git checkout prod
git merge imp
git log
commit 2672d5059a55472132f02178c7f51d8b1af0f8ea (HEAD -> prod, master, imp)
commit 1243123edc75e0abf349e1bb154d39c9f25dab2d
commit df1ca012262c26ab3a29d81b5cb6d46f6c1fc3cc
commit 66b1a08080f0db548da85471b4673c5a9f6d703f
开发更改现已在imp和prod中,包括热修复。
cat hello.txt
Hello world
cat newstuff.txt
new stuff
git checkout master
命令 :) 当有疑问时,git status
是您的好友。 - Gimbyhotfix
分支合并到production
分支上(我会使用选项--no-ff
和--log
),而不是master
分支。除非没有问题将master
合并到生产分支中,但我怀疑这点。然后再将hotfix
分支合并到master
上。 - Frodon