Stash changes to specific files

前端 未结 5 1736
情话喂你
情话喂你 2020-12-01 01:23

I have a large git project that I, stupidly, imported to eclipse and ran an autoformat on. Now, every file in the project is showing as modified. Rather than commit my for

5条回答
  •  萌比男神i
    2020-12-01 01:40

    A nice option is using the interactive stash mode.

    git stash --patch
    

    It works mostly like the interactive add mode: you are going to be presented with a series of diffs showing the changes you have in your working tree and you have to choose which files (or only certain parts of a file!) you want to stash, the rest will be left intact.

    From man git-stash:

    With --patch, you can interactively select hunks from the diff between HEAD and the working tree to be stashed. The stash entry is constructed such that its index state is the same as the index state of your repository, and its worktree contains only the changes you selected interactively. The selected changes are then rolled back from your worktree. See the "Interactive Mode" section of git-add(1) to learn how to operate the --patch mode.

    In your case, you will be able to see formatting-only hunks and stash them individually, without loosing your meaningful changes.

提交回复
热议问题