Question

I have made two lots of changes to some code in a git repo, but I would like to make separate commits for each change. The changes are not clashing, but they do overlap - that is, they make independent changes, which sometimes happen to be on the same lines. This means that git add --patch won't work.

An example of this type of change might be adding spaces after all commas to conform to a coding standard, and namespacing functions by prefixing them with a string.

Is there any smart git-related way of dealing with this kind of clash, or is the only option to start from scratch, and undo one of the changes?

Was it helpful?

Solution

You can use git add --patch for this, but you'll need to do some manual editing. When you're presented with the hunk that contains the overlapping changes selecting e (manually edit the current hunk) will allow you to make changes to exactly what is committed.

There are some risks to doing this, and there's more information about what you should avoid in the Editing Patches section of the git-add(1) man page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top