tadasajon
tadasajon

Reputation: 14866

Git - I made many changes at once -- now I want to break it down into one commit per file - how?

I've been working on my code base for a few days now. I've modified about 15 files, making various changes to each. Now I'd like to commit all my work, but I would like to break down my work into multiple smaller commits. How can I do this?

Upvotes: 0

Views: 39

Answers (2)

Roland Smith
Roland Smith

Reputation: 43533

If you want to commit all changes in one file do git add <filename> followed by git commit.

Or you can use git add's interactive mode (with the -i option), so you choose individual patches from a file to commit.

On a separate note, personally I make it a habit to commit changes often; you can always combine commits later if necessary. Remember that a commit is the smallest unit you can roll back. If you had to undo one small bit in a commit containing a couple of days of coding, it would be more time consuming and error-prone to fix. My suggestion would be to commit your changes at least at the end of the day.

Upvotes: 1

C-Otto
C-Otto

Reputation: 5843

With git gui you can select which changes to stage (staging means preparing for the next commit). I find that to be the easiest way, especially if you just want to commit individual parts of a file (even down to single lines).

Upvotes: 1

Related Questions