git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Automating git add & commit for every change individually?

From
Ggit.20.browseruk@xoxy.net <git.20.browseruk@xoxy.net>
Date
May 15, 2016, 02:01 UTC
Message-ID
<C21C71EAD3C.0000026Agit.20.BrowserUk@xoxy.net>
Hi, 
Not sure this is the right place; I couldn't find a mailing list specifically for git *users*?
Problem: Given two source trees, neither yet under source control. One (hereafter:MOD)containing extensive modifications of the other (hereafter:ORIG), I want to bring these together under source control such that I can, starting with the full MOD version, back out (and subsequently reinstate) changes individually.
And I mean individually at the 'group of lines' level; not the 'whole file' level.
Reason. The ORIG does not compile locally due to dependency on proprietary libraries I do not have access to. The MOD compiles locally and runs; but I have introduced an error that means it produces the wrong results. 
None of the changes required to remove the dependence on the proprietary libraries should have affected the functionality. Obviously, I must have touched something that wasn't required to achieve the local compile.
Some of those 'incidental' changes are obvious: the original source files contain some tabs; my editor is set to replace tabs with spaces. This shouldn't affect anything, but shows up in diffs. Some changes are habitual: manually adjusting whitespace and comments when trying to understand particular sections of code. Some are changes I made trying to achieve the compile -- addressing warnings like "Information may be lost." -- that probably weren't ultimately required to achieve the compile. These *could* affect the results produced.
Suggested solution:: Put the ORIG into git (init/add ./commit -am "Original"). Copy the modified subtree over the original. Add & Commit the changes in chunks.
Problem: It doesn't allow me to back out the changes individually; only commit sized chunks.
Suggested solution:: use git add -p to stage individual changes; and then commit it. Rinse & repeat.

Problem:This is extremely laborious and error prone. Ie. If I do git -p; {spews 377 lines of diff}; Do you want to stage this hunk. I accept: 'Y'; now that hunk is staged; but not committed. So, I have to quit out of git -p; then git commit -m {make up some reason} repeat for the next 4000 changes.

Question 1:: Is there any way to automate the staging & committing of all existing changes as individual commits? Preferably with auto-generated commit messages.
Question 2:: Is there some other way get both versions into git such that I am to be able to 'undo' individual changes to the MOD version, try the build & test; and then redo the undone change if it wasn't the one that screwed things up?
Thanks, Buk

____________________________________________________________ Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account. Check it out at http://mysecurelogon.com/manager

Message 1 of 1 in “Automating git add & commit for every change individually?”
  1. git.20.browseruk@xoxy.netMay 15, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.