假设我在分支登台想要合并 dev 并忽略 /build 文件夹中的更改:
git checkout staging
# go to staging branch
git checkout dev .
# this checkout dev file changes into staging
git reset HEAD build
# this remove added file in build folder
git clean -f
# this drops untracked files we just reseted
git checkout -- .
# this drops changed files we just rested
git status
# check is everything ok
git commit -am 'merge dev into branch'
# create a commit
git merge -s ours dev
# this create a fake merge to trick Git into thinking that a branch is already merged when doing a merge later on.
这个解决方案并不完美,因为它将所有提交合并为一个。这意味着挑选一些提交可能不合适。
但它能够避免由于重命名/新建/删除导致需要清理的构建文件夹中的大量提交。