gitui icon indicating copy to clipboard operation
gitui copied to clipboard

How to git rm --cached a file?

Open sainttttt opened this issue 11 months ago • 5 comments

Is there a way currently to git rm --cached (or any sort of delete) a file using the UI currently? I see in help it lists some sort of action as delete as Shift-D but it doesn't seem to do anything for me. I also tried searching for the actions in the code base in src/keys/key_list.rs but couldn't find a delete. Thanks!

sainttttt avatar Mar 15 '24 05:03 sainttttt

where do you expect to see such a command? in the file tree?

extrawurst avatar Mar 15 '24 11:03 extrawurst

Yeah, in the file tree. Sometimes I'd do git add . and add a bunch of files which I don't want and the only way to remove them is to git status and then copy and paste the paths and do git rm --cached or something to that effect.

sainttttt avatar Mar 15 '24 13:03 sainttttt

If the files are new (i.e have never been committed), I believe this is equivalent to git restore --staged which is already implemented via the "Unstage" action in the "Staged Changes" pane of the "Status" (first) tab.

AnonymouX47 avatar Mar 18 '24 03:03 AnonymouX47

There are cases where I have accidentally committed a file that I do not want, for example .DS_Store on macOS. I add that to my .gitignore but I also want to delete that file which shows up in the first unstaged pane. I can't do that from gitui it seems but I think that feature might be good. It's okay to do it manually for one file but if I've accidentally committed a bunch of files that I want removed or ignored it's a tedious process from the commandline.

sainttttt avatar Mar 18 '24 15:03 sainttttt

I'm also running into the same issue where I accidentally commit files I want to remove.

I've been using a similar workaround with Lazygit. By using the edit option during an interactive rebase and then dropping the unwanted files, I can effectively remove them from the commit. Combining this with Lazygit's automatic rebase makes the process a bit smoother.

It would be fantastic if gitui could incorporate a feature to remove files directly from the UI, similar to git rm --cached. This would definitely streamline the workflow for cleaning up accidental commits, especially when dealing with multiple files.

Smart-SangGe avatar Oct 01 '24 07:10 Smart-SangGe