BitBucket具有nice Pull Request (PR) process,用于检查与提交相关的代码更改。但是有时候我们发现自己处于两个相对长期存在的分支的情况,例如“ develop”和“ future_release”可能会有所不同。是时候将future_release合并到开发中了,由于这些分支之间的分歧,需要花费一些手动的精力来解决问题。
假定合并之前“ develop”和“ future_release”中的所有代码更改都已经通过同行审查,因此无需再次审查。
使用BitBucket Pull Requests UI或其他方法,是否有什么特别的方法来专门检查在合并本身中进行的手动代码更改,以解决冲突和其他差异?
答案 0 :(得分:1)
Bitbucket当前没有一种方法来查看在合并提交中进行了哪些更改,以解决合并冲突。但是,在命令行中这样做并不是很难。
这样想:有人试图进行合并,由于冲突,它们处于“未合并”状态。他们进行了一些更改来解决冲突,并提交了这些更改,然后结果是进行了新的合并提交。如果您知道此合并提交,那么您就知道他们试图合并的两件事(因为它们是合并提交的父提交)。因此,您可以将自己置于他们所处的相同未合并状态,然后在该状态与其产生的合并提交之间进行区分。
以下是一个bash脚本,可以为您完成此操作:
#!/bin/bash
# Pass the merge commit as the only argument to the script
COMMIT="$1"
# Create a temporary directory where we'll use a copy of the repo
TMP_REPO="$(mktemp -d)"
# Clone the original repo into the temporary directory, and setup the
# original repo as an "alternate" using --shared
git clone --quiet --shared . "${TMP_REPO}"
cd "${TMP_REPO}"
# Checkout the first parent of the merge commit (this is the "destination"
# commit of the merge)
git checkout --quiet "${COMMIT}^1"
# Merge the second parent (the "source" of the merge) of the merge
# commit into the first, creating "unmerged" state with conflicts
printf "GIT MERGE OUTPUT:\n\n"
git merge --quiet --no-commit "${COMMIT}^2"
# Stage everything in the working tree, including all unresolved conflicts
git add .
# Commit the changes
git commit --quiet --message "Commit all merge conflicts"
printf "\n==================================================\n\n"
# Do a diff between the commit you just created and the original merge commit
git diff --find-renames "HEAD..${COMMIT}"
rm -rf "${TMP_REPO}"
从git存储库内部运行它,将合并提交哈希作为唯一参数传递,如下所示:
$ /path/to/script.sh d29ce0c1420b18c7e8f1ce2bf3667f6609bf215d
GIT MERGE OUTPUT:
Auto-merging numbers.txt
CONFLICT (content): Merge conflict in numbers.txt
Automatic merge failed; fix conflicts and then commit the result.
==================================================
diff --git a/numbers.txt b/numbers.txt
index 18ac646..a4ab7d4 100644
--- a/numbers.txt
+++ b/numbers.txt
@@ -1,9 +1,4 @@
-<<<<<<< HEAD
+two
four
-five
six
-=======
-seven
eight
-nine
->>>>>>> d29ce0c1420b18c7e8f1ce2bf3667f6609bf215d^2