Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup before removing uncommitted changes #81

Open
llakala opened this issue Nov 5, 2024 · 0 comments
Open

Backup before removing uncommitted changes #81

llakala opened this issue Nov 5, 2024 · 0 comments

Comments

@llakala
Copy link
Owner

llakala commented Nov 5, 2024

I recently had a slip-up where I meant to unstage some changes, but did git fire instead of git demote, leading to accidentally deleting the changes.

I was able to recover, but it brought up a problem. Git is relatively unsafe with removing local changes, and there's not really a built-in way to make this safer.

I think I have a good solution: create a little script that archives the uncommited changes before removing them. Here's what I have so far:

git ls-files -z --modified | xargs -0 tar --create --gzip --file archive.tar.gz 

(I'm using long-form for command line options, since this will be in a script and succintness matters less than clarity)

This does most of what I want, but it's missing some finer detail. It doesn't function at all if there are no uncommited changes, and it's just putting the archive in the current directory. We also should consider how many archives to save. However, I'll leave this conceptual question for future me.

Once done, we can just make our git alias for deleting changes make an archive before it runs, via ! syntax. This will ensure that if we fuck up, we can quickly just check the archive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant