0

When working with JavaScript files, depending on the existing code-base, it can be common to come across code like this:

if( i == 2 ) { var bIsSupposedToBeTrue = false; // the line I actually need to fix eval('badbadbad'); }; 

This code has several issues that I need to fix to pass eslint. For example, the double equals, accounting for hoisting, bad use of semi-colons and the usage of eval.

This code also has a line of code that I want to fix for the task I am currently working on - right in the middle of the ugly code.

I want to be separate the eslint fixes from the actual fix that I originally intended to work on.

Another complicating factor is usually I want to fix the eslint errors as I work, not at the end after I have already committed the target work.

I could reset --mixed, and then git add -p, but interactive staging isn't as fine-grained as I need.

Any git advice on how to separate-out the eslint changes and the originally-intended change? Imagine if this spanned multiple files.

Something like character-wise interactive staging?

I should also add that I only wish to accomplish this via the command-line (no gui tools).

1 Answer 1

2

You can do what you want with add -p, but for this kind of thing I use git gui which allows you to select lines of text with the mouse and stage them individually. For this kind of picking, it's a good approach.

Git extensions on Windows also has a good UI for this, and SourceTree on OSX also has this functionality.

EDIT I just re-read your question. The above is true for line-by-line staging. For intra-line staging, you'll have to edit the line and stage/commit, then edit again.

EDIT 2 you can do this with add -p. Use the e command to edit the hunk manually.

Sign up to request clarification or add additional context in comments.

3 Comments

add -p doesn't work for me because it stages hunks, and I need a more-finegrained (character-wise) way of interactively staging git-scm.com/book/en/v2/Git-Tools-Interactive-Staging
@Jonathan.Brink, yes I re-read your question a moment ago and updated my answer. As git tracks content at the line level, you'll have to do this with multiple edits unfortunately.
Great! Using "e" with add -p is what I was looking for

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.