git - 将影响某些文件的更改拆分到不同的分支
问题描述
假设我一直在一个分支中处理文件 a、b、c 和 d。现在我意识到我更喜欢将我对 a 和 b 的更改放在一个分支中,而我对 c 和 d 的更改放在另一个分支中,所以从每个分支的角度来看,就好像我只修改了两个文件一样。
这可能吗?
解决方案
索引是 git 用来处理这种需求的工具。
git 会检测到您的所有更改,但不会“暂存”(例如,准备好提交),直到您这么说。
# in case you already added all or part of your changes, undo it
git reset
# if needed, create the new branch (or stay on the one you worked on from start)
git checkout -b new_branch
# now add only parts for branch 1
git add a b
git commit -m "Modified a and b"
# let's call this commit Y
# now for the second part
git checkout -b new_branch_2 master
git add c d
git commit -m "Modified c and d"
# let's say this commit Z
导致这种情况(我在这里假设您的基础分支在所有这些被调用之前 master
,其最后一次提交是 X
)
Y <<< new_branch_1
/
---X <<< master
\
Z <<< new_branch_2 <<< HEAD
最后,非常明确地说,现在您的文件a
和.b
master
Z
推荐阅读
- angular - 推送插件错误字符串资源 ID #0x0 出错
- javascript - 如何重置角度2中的输入值
- javascript - 如何修复“未捕获的类型错误:无法设置未定义的属性 '0'”
- ssl - 如何使用码头设置 2 路 SSL 身份验证连接
- go - 抓取数据时连接被拒绝
- android - 无法使用 Volley 解析 JSON 对象
- magento - Magento 网站禁用或删除“.maintenance.flag”文件的永久解决方案?
- python - Django 模型对象何时初始化?
- javascript - 无法读取未定义的属性“目标”。我想附加一个特定的元素,但它给了我错误
- unit-testing - 断言在带有参数的 JavaScript 函数的 MarkLogic 单元测试中引发错误