这就是我正在做的事情。使用npm脚本an example repo
添加预提交挂钩"is-commitable": "git status | grep 'Changes to be committed:'",
"stash-pop": "git stash pop >> /dev/null",
"stash-unstaged": "git stash save -k --include-untracked 'unstaged-stash' >> /dev/null",
"check-commitable": "npm run is-commitable || (npm run stash-pop && exit 1)",
"lint-staged": "(eslint . --fix && git add .) || (npm run stash-pop && exit 1)",
"recheck-commitable": "npm run check-commitable",
"stash-linted": "git stash save 'linted-stash' >> /dev/null",
"stash-pop-unstaged": "git stash pop stash@{1}",
"stash-pop-linted": "git read-tree stash && git stash drop",
"clean-lint-staged": "(lint-staged >> /dev/null) || exit 0"
有两行提交代码:
line1
line2
进行一些更改:
* line1-changed
* line2-changed
部分添加其中一个:
- line1
+ line1-changed
* line2-changed
运行提交和预提交挂钩被触发
藏匿-不分阶段
- line1
+ line1-changed
line2(changed part been stashed in unstaged-stash)
棉绒阶
- line1
+ line1-fixed
line2(changed part been stashed in unstaged-stash)
藏匿-LINTED
line1(changed and fixed part been stashed in linted-stash)
line2(changed part been stashed in unstaged-stash)
藏匿-POP-不分阶段
line1(changed and fixed part been stashed in linted-stash)
* line2-changed
藏匿-POP-LINTED
- line1
+ line1-fixed
* line1-changed
* line2-changed
清洁绒布上演
- line1
+ line1-fixed
* line2-fixed
最后两步并不完美。
我想得到
- line1
+ line1-fixed
* line2-changed
但现在我只能得到
- line1
+ line1-fixed
* line1-changed
* line2-changed
或
- line1
+ line1-fixed
* line2-fixed
那么我能找到一种方法来以编程方式git checkout一个文件只有分阶段的行吗?
或者放弃最后一步找到修复最后第二步的方法