{"id":26364782,"url":"https://github.com/lightandlight/git-ustash","last_synced_at":"2025-03-16T19:28:21.500Z","repository":{"id":229427180,"uuid":"775961640","full_name":"LightAndLight/git-ustash","owner":"LightAndLight","description":"Save and restore unstaged changes in Git.","archived":false,"fork":false,"pushed_at":"2024-03-27T08:19:11.000Z","size":30,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-27T09:33:51.775Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LightAndLight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-22T11:54:50.000Z","updated_at":"2024-03-25T13:35:15.000Z","dependencies_parsed_at":"2024-03-24T10:22:53.085Z","dependency_job_id":"247532ca-30ac-4c1c-a967-fce6ce333a1a","html_url":"https://github.com/LightAndLight/git-ustash","commit_stats":null,"previous_names":["lightandlight/git-ustash"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LightAndLight%2Fgit-ustash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LightAndLight%2Fgit-ustash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LightAndLight%2Fgit-ustash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LightAndLight%2Fgit-ustash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LightAndLight","download_url":"https://codeload.github.com/LightAndLight/git-ustash/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243919156,"owners_count":20368841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-16T19:28:20.917Z","updated_at":"2025-03-16T19:28:21.486Z","avatar_url":"https://github.com/LightAndLight.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `git-ustash`\n\n**Note: [`git-format-staged`](https://github.com/LightAndLight/git-format-staged) solves my [original problem](#background) much better than `git-ustash` does.**\n\nSave and restore unstaged changes in Git.\n\n`git-ustash save` saves all unstaged changes, and *only* unstaged changes.\nIt's an error to call `git-ustash save` while there are previously-saved unstaged changes (i.e. the \"max stash size\" is 1).\n\n`git-ustash restore` restores the previously-saved unstaged changes.\n\n## Installation\n\nTry using Nix: `nix run github:LightAndLight/git-ustash -- --help`\n\nAdd to a Nix Flake:\n\n```nix\n{\n  inputs = {\n    flake-utils.url = \"github:numtide/flake-utils\";\n    git-ustash.url = \"github:LightAndLight/git-ustash\";\n  };\n  outputs = { self, nixpkgs, flake-utils, git-ustash }:\n    flake-utils.lib.eachDefaultSystem (system:\n      let\n        pkgs = import nixpkgs { inherit system; };\n      in {\n        devShell = pkgs.mkShell {\n          buildInputs = with pkgs; [\n            git-ustash.packages.${system}.default\n          ];\n        };\n      }\n    );\n}\n```\n\n## Background\n\nThis is something I've wanted when writing [pre-commit hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) that do auto-formatting.\nThe goal of a pre-commit auto-formatter is to format staged files without affecting any other files.\n`git diff --cached --name-only` gives the list of staged files, but if you *just* format them without any other preparation then you can cause issues with unstaged files.\nFor example, if you use `git add -p` to stage a file using a partial patch, then you will have the rest of the file unstaged.\nHow to format just the staged copy of the file?\nThe unstaged version (with the remainder of the changes) is the only one on disk.\nUsing `git stash --keep-index` almost does the right thing; it gets the unstaged files out of the way so it looks like you are free to work on just the staged files.\nUnfortunately it also stashes the staged files, so that when you auto-format the staged files, re-add them to the index, and pop from the stash, the formatted files are overwritten by the stash.\n[This answer on StackOverflow](https://stackoverflow.com/a/71222518/2884502) looked promising, but `git stash push --staged` fails with an error when I use it in the `git add -p` aforementioned situation.\n\n`git-ustash` doesn't fully solve the pre-commit auto-formatter problem for me, but it has revealed the next step along the way.\n`git-ustash save; formatCode; git add -u; git-ustash restore` restores unformatted unstaged files.\nWhen some changes are split across staged and unstaged versions of a file (the `git add -p` workflow), formatting that's applied to the staged version is \"lost\" on the unstaged version.\nThis makes the diff after `git-ustash restore` rather noisy and adds busywork into the commit workflow.\nI think the next step would be a program that can modify a staged file and backport the diff to the file's unstaged counterpart.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightandlight%2Fgit-ustash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flightandlight%2Fgit-ustash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightandlight%2Fgit-ustash/lists"}