git - Can you cherry-pick a hunk or hunks from within a git commit?
问题描述
When I do stage commits in my workspace I usually use the -p
option to go through each hunk of the changes. I find this useful to confirm my changes and as a check on typos and other silly errors.
I usually rebase
in my open source development work when a dev branch gets stale. However, sometimes I want to test out something on a throw away branch in my workspace and I don't want the entire branch because it is long and contains many commits that are not yet merged. I could git cherry-pick
but that appears to grab the entire commit. Sometimes these commits are large and I don't want the entire thing.
Is there any way to grab the commit via cherry-pick
but inspect the commit hunk by hunk as it is applied to a staging area before committing?
Presumably the user then stages only the components of the commit that they want.
解决方案
不确定这是最简单的方法,但原子上它可能看起来像
# first you cherry-pick without committing
git cherry-pick -n <commit-hash>
# then you unstage everything
git reset
# and stage hunk by hunk as usual
git add -p
# finally you discard everything else
git stash --keep-index
推荐阅读
- node.js - 在发送之前从soap请求xml中删除并覆盖一些属性
- c++ - 如果您的团队同意一组别名,那么对 STL 容器使用类型别名是不好的做法吗?
- android - Android Studio 在 XML 自动完成中创建 HTML 标签
- typescript - 如何在自定义选项卡导航器路由器中设置默认参数
- android - 无法从命令行使用 bundletool 构建 android app bundle
- python - Python Django:每次点击每行从数组中的按钮分配变量
- dart - webview_flutter 和 flutter_webview_plugin 哪个更好
- react-native - 当我 react-native run-ios bundle 不工作时
- python - 如何遍历包含多个列表和元组的列表
- vue.js - 如何使用 vue cli 3 构建电子应用程序?