2

I like to save my progress while working on large commits. But when I commit, my project naturally loses all of its highlighting of changes (lines and files) in IntelliJ. I am not very used to git so this may be an easy or hard question, but I want to commit my changes, but keep the highlighting of changes since my last big commit, so I think I would need to choose which commit to start highlighting from somehow.

Is there a way to do this, and can I be provided specific steps to do it?

I want to do this with as little damage to my git history as possible. When I am doing this I am doing it as a single developer. I am not very used to git, so any potential problems with any solutions would be good to know as well.

6
  • 3
    Git itself is not doing this highlighting - that's entirely up to the IDE. Whether there's some way to make IntelliJ behave the way you want, I don't know, but committing often in Git is usually a good idea at the Git level. Commented Dec 4, 2022 at 8:47
  • Is git diff your-last-big-commit what you are looking for? Commented Dec 4, 2022 at 9:23
  • while working on large commits - No, no, no! SMALL COMMITS. You should always work with small commits. And I get the sense that you do not rewrite the history often. You should. All the time! (before things are pushed remotely). If you are not constantly rewriting history you are using git wrong. Every day you're interacting with git you should at least rewrite history a double digit number of timer. Embrace rewriting history. And making small commits. You should never, ever create large commits (unless absolutely required by say an api change that breaks everything or something like that). Commented Dec 4, 2022 at 12:16
  • @torek I know it is not git doing the highlighting, but the IDE reading the git changes since my last commit. I thought maybe there was a technique to commit my latest small commit, then "start" from a previous big commit (while still preserving my changes since then somehow) so I may see the highlighted differences between my current work and the last big commit in my IDE while continuing with the files from latest small commit. Commented Dec 5, 2022 at 6:02
  • @torek I think I might be able to do it all manually by making a manual back of my files, then committing, then starting from a previous big commit, then copying the manually backed up files over the files from that last big commit. I don’t know if that would work, and it sort of seems like a trick that might cause problems, but the IDE might show highlighting based on the changes from the last big commit. Commented Dec 5, 2022 at 6:02

1 Answer 1

2

While working on large commit is not the recommended best practice, you can:

  • save your work in progress through commits
  • keep your current diffs against your last commits

For that:

  • create a "wip" (for "work in progress") branch from your current dev branch (after your last small commit)
  • reset soft dev to your previous large commit

See IntelliJ "Reset a branch to a specific commit".

After the last soft reset, all your files should reflect the diff against said previous large commit

Whenever you want to commit again:

  • reset soft dev to your wip
  • add and commit
  • reset (hard) wip to your dev (to point to that last small commit)
  • reset soft dev to your previous large commit (to see again all your diffs compared to said previous large commit)
Sign up to request clarification or add additional context in comments.

3 Comments

It is going to take me a tiny bit to work through this and make sure I don’t break something, and to test it in the IDE instead of the command line, but thank you for the easy to follow steps.
@Hasley Those steps should be achievable in the IDE, using the IntelliJ "Reset a branch to a specific commit" link.
@Hasley With regards to safeguarding against breaking something, I highly recommend using git test which lets you verify that all commits on a branch build/tests/lints/etc successfully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.