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

Re: yet another workflow question...

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Oct 11, 2007, 14:37 UTC
Message-ID
<470E3545.4060005@viscovery.net>
In-Reply-To
<e2a1d0aa0710110711m77ca967bmd1d5ffd5d3099aab@mail.gmail.com>
Patrick Doyle schrieb:
Show 20 quoted lines
> I've been working on my project and I realize that I have 3-4 files
> modified with two orthogonal sets of changes.  (I didn't realize this
> until I said to myself -- "Self, I should really check in these files
> before I go too much further down this path".)  So I start "git
> diff"-ing the files and I find that most files have differences
> related to only one change or the other, but one file has differences
> related to both changes.
> 
> What do others do in this situation?
> a) Not allow themselves to get into this situation in the first place
> by careful planning?
> 
> b) Copy the file to "file.bothchanges", edit out one set of changes,
> commit that with one log message, edit back in the other set of
> changes, edit in the other set of changes, commit that with another
> log message?
> 
> c) Use some sort of automation to do option (b) for them?
> 
> d) Something else?
Use git-gui.

Stage the files relevant for the first change. In the file where you have an overlap with the second change, you can right-click in the diff pane and select "Stage Hunk for Commit" on the hunk relevant for the first change.[*]

Commit with a message.
Stage the remaining changes and commit again.

At this point, I usually check out HEAD~1, i.e. the state *without* the second change, and compile and test to make sure I have a bisectable history.

[*] Of course, this works only if the changes are not in the same hunk. If there are at least 3 unmodified lines between the changes, you can choose "Less context" until they are in separate hunks.

-- Hannes
Previous: Steffen ProhaskaNext: Wincent Colaiuta
Message 4 of 9 in “yet another workflow question...”
  1. Patrick DoyleOct 11, 2007
  2. David KastrupOct 11, 2007
  3. Steffen ProhaskaOct 11, 2007
  4. Johannes SixtOct 11, 2007
  5. Wincent ColaiutaOct 11, 2007
  6. Andy ParkinsOct 11, 2007
  7. Andreas EricssonOct 11, 2007
  8. Jing XueOct 11, 2007
  9. Andy ParkinsOct 12, 2007

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.