Git: commit partial changes Git: commit partial changes git git

Git: commit partial changes


You are doing exactly what I've done in the past, and I even recreated your entire experiment on a UNIX machine and it worked just as expected.

I suspect your editor is changing the line endings in the diff hunk when it saves.


This doesn’t feel like the absolute “git way” to do it this since git loves the command line, but here’s what i do:

Git comes bundled with git gui – you can start it by running just that command. There you can select your unstaged file, mark the lines you want to commit and click “stages lines for commit”. If you want it to behave more like a command-line tool, you can run git gui citool, which has the effect that the ui will close when you commit.

Partial staging with git gui

Note that this tool is properly integrated with git. You don’t need to make your commit in this ui. You can just stage the relevant lines, close it, maybe do some more git add and then commit via the command line.

In general I love the git comand line interface and even though I am not necessarily a shell fan, I just got to love it after a while. I tried multiple GUIs and threw them all away because they can’t compete with the git command line interface. But for git add -p I would definitely say that that is a task for a GUI. Doing partial commits is just way easier with git gui. Same goes for complex history browsing. gitk (also shipped with git) does a way better job there than git log --graph -p (as long as you really need to understand the tree and don’t quite now about the state of the history).

Note: But you still seem to be doing everything right – I tried what you did and have to agree with Ben Jackson. That should definitely work. Your editor must be screwing something up.

Final Note: You seem to be using the git command line with the standard windows cmd terminal. I strongly recommend switching to mintty. Download the msys version, put it in your Program Files\Git\bin directory and run it (create a shortcut) with mintty -. This will get you the same shell, but with better everything (especially better resizing and copy&paste).