lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Toggle hide/show untracked files

Open hzwangzi123456 opened this issue 4 years ago • 29 comments

How to hide the untracked files in files?

hzwangzi123456 avatar Aug 29 '20 00:08 hzwangzi123456

You mean like gitignore?

glvr182 avatar Aug 29 '20 23:08 glvr182

This can be done at the repo level with the git config. Closing due to staleness

jesseduffield avatar Oct 06 '20 10:10 jesseduffield

need toggle hide untracked files feature

epheien avatar Apr 12 '21 11:04 epheien

@epheien do you mean from within lazygit?

jesseduffield avatar Apr 12 '21 11:04 jesseduffield

@epheien do you mean from within lazygit?

yes, I need not change git config and simply toggle show / hide untracked files, for example:

git status -uno # hide
git status # show

Some git client has this feature, such as Fork.app on macOS.

epheien avatar Apr 12 '21 11:04 epheien

I've updated the issue description for this use case

jesseduffield avatar Apr 12 '21 12:04 jesseduffield

I was just trying out lazygit and this was an immediate issue since I had been testing npm apps in a repo but not made any commits so node_modules was still hanging around and the entire listing for that directory made the Files panel unusable upon first opening.

image

I thought that having a hide untracked files setting would be the solution for me however there are perhaps some UX improvements that could help as well.

Firstly I found the discussion in #1712 about how to navigate panels and it was non-obvious to me to use Enter to collapse a dir, I kept trying arrow keys. Also how do you navigate to top or bottom of the file panel since PgUp or PgDn navigates in the change panel.

One small improvement might be for untracked directories (or very long directory listings) to be collapsed by default?

image

A further improvement would be to sort by tracked first and prefixing dirs with ?? or M. This would emulate the short git status. (side-note I feel dot prefix files really should sort first):

image

I hope this helps in deciding what to do with this issue

cas-- avatar Feb 08 '22 11:02 cas--

I would like to add that I would like the option to add the untracked file I see.

dcd-arnold avatar May 13 '22 11:05 dcd-arnold

I would like to add that I would like the option to add the untracked file I see.

Add it as in "stage it"? Pressing space should do it.

mark2185 avatar May 13 '22 11:05 mark2185

hi @mark2185, thanks for getting back to me. I have set

[status]
showuntrackedfiles = no

in my git config. I don't want to see untracked files in git status on command line. I add the files I need (seeing all files on the commandline with ls).

However, I do not see untracked files in lazygit. My guess is, lazygit picks that setting up. But I don't see all or untracked files in lazygit, hence I can't add them on demand. I leave lazygit, add the files and start lazygit again to continue to work on the commit. I would like to able to switch view of (un-)tracked files within lazygit so I don't have to leave to the command line an back. I hope that explanation clears things up a bit.

dcd-arnold avatar May 16 '22 07:05 dcd-arnold

Oh yes, that clears things up quite a bit.

@jesseduffield maybe the showuntrackedfiles setting should only change the initial state of the filter?

Those with said setting will have the filter Show only staged files, others will have it set to no filter, and the Files pane should always show all the files and then filter them out if needed?

mark2185 avatar May 16 '22 07:05 mark2185

I agree about showuntrackedfiles determining the initial state, but in this case Show only staged files won't do because we still want to show unstaged, tracked files.

jesseduffield avatar May 16 '22 07:05 jesseduffield

Oh yeah, forgot about that tiny detail.

Well then, having the filters togglable? I know toggles aren't yet a feature, but hey.

[X] Show staged    files
[X] Show unstaged  files
[X] Show tracked   files
[X] Show untracked files

But it does seem like it complicates stuff more than it does simplify.

mark2185 avatar May 16 '22 07:05 mark2185

I'm thinking we could have a 'show staged / show unstaged / show all' option as well as a separate toggle for 'show untracked'. So we'd have this logic:

staged unstaged all
show untracked hide untracked show untracked show untracked
hide untracked hide untracked hide untracked hide untracked

Where the column headers are for the staged/unstaged/all option and the row headers are for the 'show untracked' toggle, and the cells in the middle describe whether we actually show untracked files given a combination of the two options.

jesseduffield avatar May 16 '22 07:05 jesseduffield

Yeah, that makes more sense. :smile:

mark2185 avatar May 16 '22 07:05 mark2185

Now we just need that toggle feature!

jesseduffield avatar May 16 '22 07:05 jesseduffield

I say we wait for lazydocker to get that and then steal it. :full_moon_with_face:

mark2185 avatar May 16 '22 07:05 mark2185

hahaha

jesseduffield avatar May 16 '22 07:05 jesseduffield

But what about hiding specific untracked folders that won't be commited in any case? Or hiding only untracked files inside a specific folder? For example: I have a project that I am working on, and I have lots of testing data, meta files, png, txt, etc... It can pile up to a several GBs with thousands of files. Navigating with this pile to stage specific file is quite hard. And most of the time my day starts with me closing all folders except source code, since it has no similar problems (:

I have following structure:

ImportantFolderRoot/ImportantFolder1/,,, ImportantFolderRoot/ImportantFolder2/... ImportantFolderRoot/ImportantFile1 ImportantFolderRoot/ImportantFile2 ImportantFolderRoot/UnstagedTestingFile1 ImportantFolderRoot/... ImportantFolderRoot/UnstagedTestingFolder/...

and so on.

all500234765 avatar May 17 '22 03:05 all500234765

@all500234765 would that not be a good candidate for inclusion in the gitignore file?

jesseduffield avatar May 17 '22 04:05 jesseduffield

Then it will have merging issues because those files are local and git repo shouldn't know anything about them until commited

all500234765 avatar May 17 '22 10:05 all500234765

Chiming in to describe my use-case for this. I store my config dotfiles in a bare repo at ~/.dotfiles, and typically interact with it like lazygit --git-dir="$HOME/.dotfiles/" --work-tree="$HOME". Given that the entire home directory is the worktree, I have status.showUntrackedFiles disabled for this repo.

Whenever I want to add a new file to the repo I find myself reaching for regular git to add it as I can't find a way to do that in lazygit.

I don't necessarily need or even want a toggle to show untracked files as that will certainly break things in my situation as it contains every file in my home directory. I simply need a way to add a currently untracked file - whether by providing a fill path or navigating to it and selecting it somehow, the mechanism wouldn't matter a whole lot to me. It would just let me not reach for raw git.

StarTerrarium avatar Dec 04 '22 13:12 StarTerrarium

It would just let me not reach for raw git.

Would running a custom command through : suffice?

Just :git add <file>, but just to point out that there is no autocompletion.

mark2185 avatar Dec 04 '22 13:12 mark2185

I sort of assumed that wouldn't give me a lot of benefits because I thought I'd need to add in the whole --git-dir="$HOME/.dotfiles/" --work-tree="$HOME" again to that command.. But it turns out I was wrong.

:git add ~/test does indeed work as expected - so this gets me basically where I wanted, just without ideal UX. Thanks a bunch for the suggestion

StarTerrarium avatar Dec 04 '22 13:12 StarTerrarium

as well as a separate toggle for 'show untracked'.

I would love this! I often find myself in cases where I only want to see tracked files but I don't yet want to add the untracked files to gitignore.

AckslD avatar Aug 24 '23 23:08 AckslD

I'm personally doing this but LazyGit needs to be restarted to refresh, could I refresh lazyy without restarting it?:

customCommands:
  - key: "u"
    command: "git config status.showUntrackedFiles {{.Form.Value}}"
    context: "global"
    prompts:
      - type: "menu"
        title: "Show untracked?"
        key: "Value"
        options:
          - value: "yes"
            name: "Yes"
            description: "Show untracked files"
          - value: "no"
            name: "No"
            description: "Hide untracked files"

melMass avatar Apr 01 '24 17:04 melMass

@melMass try pressing shift+R from the files view after running that command, it should refresh the files and that should make use of the new git config value.

jesseduffield avatar Apr 01 '24 22:04 jesseduffield

Thanks @jesseduffield ! The values of my custom commands were wrong (it's either normal or all not yes), but I still can't seem to be able to refresh the file list (I tried shift R and r which is what the help shows):

customCommands:
  - key: "u"
    command: "git config status.showUntrackedFiles {{.Form.Value}}"
    context: "global"
    prompts:
      - type: "menu"
        title: "Show untracked?"
        key: "Value"
        options:
          - value: "normal"
            name: "Normal"
            description: "Show untracked files"
          - value: "all"
            name: "All"
            description: "Show untracked files (individual files in directories)"
          - value: "no"
            name: "No"
            description: "Hide untracked files"

melMass avatar Apr 02 '24 02:04 melMass