如何以编程方式git部分检出文件

时间:2017-05-20 02:27:50

标签: node.js git eslint pre-commit-hook pre-commit

这就是我正在做的事情。使用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"

实施例

  1. 有两行提交代码:

    line1
    line2
    
  2. 进行一些更改:

    * line1-changed
    * line2-changed
    
  3. 部分添加其中一个:

    - line1
    + line1-changed
    * line2-changed
    
  4. 运行提交和预提交挂钩被触发

    • 藏匿-不分阶段

      - 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
      
  5. 问题

    最后两步并不完美。

    预期结果

    我想得到

    - line1
    + line1-fixed
    * line2-changed
    

    实际结果

    但现在我只能得到

    - line1
    + line1-fixed
    * line1-changed
    * line2-changed
    

    - line1
    + line1-fixed
    * line2-fixed
    

    需要帮助

    那么我能找到一种方法来以编程方式git checkout一个文件只有分阶段的行吗?

    或者放弃最后一步找到修复最后第二步的方法

0 个答案:

没有答案