What is the fastest way to unstage parts of a new file in git?

前端 未结 4 1777
旧巷少年郎
旧巷少年郎 2021-02-12 10:36

When I want to split up a new file into several commits I can git add -N and then interactively stage lines using git gui. When I make a m

4条回答
  •  隐瞒了意图╮
    2021-02-12 11:30

    I just ran into the same issue: I had just committed a new file, and I wanted to unstage some of the lines in that file and have those as a separate commit. The solution I worked out was:

    • Start on the commit that adds the new file
    • Remove the lines you wanted to unstage in the source file, stage those changes and git commit -m 'REVERTME'
    • Create a new commit that reverts that latest commit: git revert HEAD
    • Use git rebase -i to fixup the first new commit, and optionally reword the revert commit.

提交回复
热议问题