3

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?

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443

1 Answers1

1

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Do you really mean to stage all pending changes? Or rather to *stash* them? – Daniel Hilgarth Nov 08 '11 at 13:06
  • What do you mean by non-indexed changes? "changes only on your hard drive" -> My complete git repo is only on my hard drive, so this explanation is rather ambiguous :-) – Daniel Hilgarth Nov 08 '11 at 13:08
  • @DanielHilgarth: yes stash (typo). As for the "non-indexed" part, I mean file that are unknown to git (never added, never committed). – VonC Nov 08 '11 at 13:31
  • ok. Is the `reset --hard HEAD` really necessary? AFAIK `git stash` already resets the working copy. – Daniel Hilgarth Nov 08 '11 at 13:34
  • 1
    I just tested it: stashed the changes (this automatically reset my working directory) and did the rest as you said. Worked like a charm! :) Thanks a lot – Daniel Hilgarth Nov 08 '11 at 13:39