質問

I have five files that have been changed: 1-3 need to be in a single commit, while 4 and 5 need to be different commits entirely, so I need 3 separate commits in all. How do I use git stash to accomplish the following:

commit1:
  file1
  file2
  file3
commit2:
  file4
commit3:
  file5

without losing any of my changes? Thanks!

役に立ちましたか?

解決

If I'm reading your question correctly, you don't need to use git stash at all...

You could just add them and commit them separately:

git add file1 file2 file3
git commit -m "first message"
git add file4
git commit -m "second message"
git add file5
git commit -m "third message"

他のヒント

If you're using git stash you don't need to worry about separate commits at the moment. Run the stash command, then do whatever else it is you need to do, then pop your changes back from the stash and then make your commits how you want them.

You have two other alternatives. 1) create a new branch and make your commits there. Then return back to your current branch. At some point merge. 2) Create your commits then rebase. This is probably not what you want to do.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top