我正在努力理解以下行为如何在 git 中是一件好事。请参阅下面的示例,以帮助说明我的问题。很多时候,我的团队和我自己都在将更改/提交进入我们不想去那里的分支。
> git init sandbox && cd sandbox
> echo "data a" > a.txt && echo "data b" > b.txt
> git add -A && git commit -a -m "initial population"
[master (root-commit) d7eb6af] initial population
2 files changed, 2 insertions(+)
create mode 100644 a.txt
create mode 100644 b.txt
> git branch branch1
> echo "more data a" >> a.txt && git commit -a -m "changed a.txt on master"
[master 11eb82a] changed a.txt on master
1 file changed, 1 insertion(+)
> git branch branch2 && git checkout branch2
Switched to branch 'branch2'
> echo "more data b" >> b.txt && git commit -a -m "changed b.txt on branch2"
[branch2 25b38db] changed b.txt on branch2
1 file changed, 1 insertion(+)
> git checkout branch1
Switched to branch 'branch1'
> git merge branch2
Updating d7eb6af..25b38db
Fast-forward
a.txt | 1 +
b.txt | 1 +
2 files changed, 2 insertions(+)
请注意,在上面,a.txt 在合并中更新,即使它在 branch2 上没有被触及/修改。在上述场景中,我希望 git 能够智能地识别出分支 2 上的 a.txt 没有更改,因此在将更新应用于分支 1 时,不要进行这些更改。
有什么我做错了吗?是的,我可以挑选,对于这个简单的例子,我知道我做了什么,但在实际情况下是不现实的,因为变化要大得多,你不知道可能会受到什么影响。
需要明确的是,我不希望 git 出现这种行为。