1

You probably know that: You work on a method in class X and then notice, that you need to change a (often small declarative or even structural) thing in a number of files in order to work better for your method as well as the whole project in the future.

In my case, I have moved the class along with related classes to another package in order to protect my method from outside access, but keep it accessible to classes in my package.

Now I am always in the dilemma of how to commit. Moving a class triggers many changes in many classes, changes imports etc. Commiting and writing a message that describes both the moving a number of files and the newly added method is not encouraged, because not pure. I am in the middle of the method, so I could delete the method I am working on and commit the structural change. Then paste it afterwards and do a second commit.

How do you proceed in that case? That is one example, however I face that issue quite often.

IrApp
  • 11
  • 2
  • Could be a duplicate of [Commit only part of a file in Git](https://stackoverflow.com/questions/1085162/commit-only-part-of-a-file-in-git/31649973) – DrosvarG Aug 16 '19 at 12:15
  • 2
    Possible duplicate of [Commit only part of a file in Git](https://stackoverflow.com/questions/1085162/commit-only-part-of-a-file-in-git) – DrosvarG Aug 16 '19 at 12:15

1 Answers1

1

When you are ready to commit and you realize that the change is too large/complex for one commit, you can always use git add -p to go through your diff and select what to commit.

On the other hand, it is usually strongly discouraged to fabricate commits that do not compile or work as intended. So you might be better off committing the whole thing.

mattmilten
  • 6,242
  • 3
  • 35
  • 65