Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

stage part of line

Is it possible to stage only part of a line?

Scenario: I am refactoring my unit tests from Rhino.Mocks to NSubstitute, so I am changing a lot of code like this:

mock.AssertWasCalled(x => x.MyMetod());

to this:

mock.Received().MyMetod();

Now, I am not finished with this refactoring, but while I am at it, I come across a typo in one of my methods and fix it, so the code will look like this:

mock.Received().MyMethod();

Now, the renaming of this method is completely unrelated to the refactoring from Rhino.Mocks to NSubstitute, so I just would like to commit this change in its own revision. Is this possible somehow?

Upvotes: 4

Views: 145

Answers (1)

VonC
VonC

Reputation: 1328322

Considering there is no telling how much you already modified your code, I would rather:

  • stash all my pending changes
  • reset --hard HEAD (make sure you don't have non-indexed changes, as in "changes only on your hard drive, never added to a Git repo": they would be deleted)
  • make the refactoring, add it and commit it
  • git stash pop: restore the changes
  • fix the last MyMetod call that your pending changes were still using

Upvotes: 1

Related Questions