Adding a gitignore after the fact is difficult to clean up
Description
When adding files to the gitignore after jj has recognized them as new files, it is rather difficult to remove them from the automatically created commit again.
I ended up using git to manually create a new commit and work from there, but ideally, jj would recognize when a file added in the current commit has also been added to the gitignore.
Steps to Reproduce the Problem
- create a new repository somewhere with
git init jj init --git-repo=.touch testfilejj stecho "testfile" > .gitignorejj st
Expected Behavior
Ideally, the testfile would not be part of the created commit.
Actual Behavior
testfile as well as .gitignore are marked as "added" in the commit.
Specifications
- Platform:
NixOS 23.11 - Version:
jj 0.13.0
5. `echo "testfile" > .gitignore` 6. `jj st`
After the step 5, you'll need to run jj untrack testfile.
Perhaps, jj status can show hint for the added files matching .gitignore.
Ah thanks, I guess I missed untrack somehow. Adding a hint would be a good idea I think. I know some repos make use of the "committed but ignored file" behavior of git, but I think for most people it is unexpected.
This has tripped me up before, and while jj untrack testfile works, it feel unintuitive compared to git's immediate respect of .gitignore.
It seems just the opposite of #3204.
Does jj have its own ignore file also?
We may want to consider the parent of the working copy when snapshotting the working copy. We currently only consider the previous snapshot of the working copy itself.
Does
jjhave its own ignore file also?
No. Maybe we will one day, or maybe not.
Is there special handling for undo when the ignore file is involved?
Is there special handling for
undowhen the ignore file is involved?
No
This has tripped me up before, and while
jj untrack testfileworks, it feel unintuitive compared to git's immediate respect of.gitignore.
It makes sense though as it inverses the git add pattern which we cover with auto-tracking. But a hint for jj st is definitely a good idea.
Encountered this as a fresh git convert. What compounded my confusion is that the documentation is outdated: https://github.com/martinvonz/jj/blob/6498a0cf8a5053e8a55fb503800e11b00953ecdc/docs/working-copy.md?plain=1#L60-L61 and contradicts an existing test case https://github.com/martinvonz/jj/blob/8e4d1af98eccf1ed8a79a7ddf9500467aa7684f5/cli/tests/test_gitignores.rs#L41-L47
What compounded my confusion is that the documentation is outdated:
Thanks for letting us know! I'll send a PR to fix it.
+1 would love a hint to use untrack. Would it be better for status to include a hint (a) every time you run it while a file in the repo is committed + ignored or (b) once only after jj detects a new (git)ignore edit disagrees with the set of committed files?