When committing changes to your source control system, it’s considered good practice to only resolve a single task with each commit. There are several advantages to this approach:
- The history reads like a list of tasks that were accomplished
- Each commit can be easily reviewed, as it only does one thing
- Commits can be easily reverted or cherry-picked
However, when working with source code, it’s temping to sneak-in another small change into your current commit. Take the following example:
However, these are two independent tasks. If the implementation of the computePi method was reverted (or did not pass code review), I would still expect the typo to be corrected. While I could stash the work I’m doing, fix the typo, retrieve the stash and continue, the overhead of that workflow would likely deter me. With Eclipse Git (EGit) there is a much easier way.
From the staging view, double-click on the file. A compare dialog will appear. On the left are your current changes; on the right is the currently staged work. You can now copy changes from the left to the right, effectively staging parts of your file. In this case I will stage the correction to the method name.