{"thread":{"id":"58137","subject":"Revert and reset and very damaging Git commands","startedAt":"2022-07-11T19:52:19Z","lastAt":"2022-07-11T23:20:43Z","messageCount":3,"participants":["Gerriko io","brian m. carlson","Thomas Guyot"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"458814","messageId":"CALF=2AMDTa48sYdrPjc_i9UyaZfvGKhR9OvknYfLywgtj8AM_g@mail.gmail.com","threadId":"58137","inReplyTo":null,"subject":"Revert and reset and very damaging Git commands","fromName":"Gerriko io","fromEmail":"gerriko.iot@gmail.com","sentAt":"2022-07-11T19:52:05Z","receivedAt":"2022-07-11T19:52:19Z","isPatch":false,"sender":{"key":"gerriko.iot@gmail.com","avatar":null},"body":"As a noob I have managed to completely delete all my local folder\ncontents just by misusing reset and revert commands. Un-be-lievable!\nAnd no matter how many times I've tried I cannot return to where I\nwas. The git reflog is not that helpful either... and only shows\nresets and not revert histories.\n\nGosh this is not good.\n\nWhy are these commands bypassing all the fundamentals of a computer\nOS. Surely if a file is deleted it should end up in the computer's\nrubbish bin. Not deleted permanently without a trace.\n\nIf that is the intent then there needs to be warnings etc. for deletes\nand overwrites.\n\nI'm just amazed that all the basics of software design are ignored for\nthe sake of convenience and speed.\n"},{"id":"458827","messageId":"YsyYtOIpIU29OMN/@tapette.crustytoothpaste.net","threadId":"58137","inReplyTo":"CALF=2AMDTa48sYdrPjc_i9UyaZfvGKhR9OvknYfLywgtj8AM_g@mail.gmail.com","subject":"Re: Revert and reset and very damaging Git commands","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-07-11T21:40:04Z","receivedAt":"2022-07-11T21:40:36Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-07-11 at 19:52:05, Gerriko io wrote:\n> As a noob I have managed to completely delete all my local folder\n> contents just by misusing reset and revert commands. Un-be-lievable!\n> And no matter how many times I've tried I cannot return to where I\n> was. The git reflog is not that helpful either... and only shows\n> resets and not revert histories.\n\nThe reflog should indeed keep track of every revision that's checked\nout, including reverts.  Reverts act as an additional commit on top of\nyour code, so they are part of your history.  You can use `git log` or\n`git log -p` to view the history of the current branch, including any\nreverts.\n\nIf you want to check out a file (say FILE) from an older revision (call\nit REV), you can do `git checkout REV FILE`, and that will stage that\ncopy of the file and place it in the working tree.  That can be useful\nto recover an older version when you've done a revert (or even when you\njust want the older version back).\n\nIf you have files you've blown away with `git reset --hard` and you've\nadded them to the repository, they can be recovered by using `git fsck\n--lost-found` to store them into `.git/lost-found` if they're not\nreferenced by your history.  If they are referenced by your history,\nthen they can be accessed using `git checkout` as I mentioned above.  If\nthey've never been added, then they're gone for good unless you use some\nsort of deleted file recovery software.\n\n> Gosh this is not good.\n> \n> Why are these commands bypassing all the fundamentals of a computer\n> OS. Surely if a file is deleted it should end up in the computer's\n> rubbish bin. Not deleted permanently without a trace.\n\nIn general, the programmatic interfaces used to create and delete files\ndon't use the user trash can.  That's because many programs create and\ndelete extremely large numbers of temporary files (Git included) and it\nwould be silly to expose those to the user, since the user trash can is\ndesigned to handle files that the user specifically might want to\nrecover.  There is also no standard portable interface for placing files\ninto the user trash can, while there are standard portable interfaces\nfor actually removing files.\n\nAlso, traditionally, on Unix systems, deleting files has happened\nwithout prompting, and Git is designed for Unix systems.\n\n> If that is the intent then there needs to be warnings etc. for deletes\n> and overwrites.\n> \n> I'm just amazed that all the basics of software design are ignored for\n> the sake of convenience and speed.\n\nGit is a command-line tool.  Command-line tools on Unix perform the task\nas specified silently unless there's an error.\n\nIf Git prompted when using `git reset` for each file, then it would be\nunusable in a script, and people do frequently use Git in scripts.\nAlso, when using something like `git clean` to clean build artifacts,\nthere might be tens or hundreds of thousands of build files, and nobody\nwould want to be prompted for each one.\n\nIn general, you need to be very careful with `git reset` and very\nespecially with `git reset --hard`.  The latter does blow away files\nwithout notice and is very dangerous if you're not careful.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"458836","messageId":"ba1eb825-89cf-84c0-864e-5307376ccba1@gmail.com","threadId":"58137","inReplyTo":"YsyYtOIpIU29OMN/@tapette.crustytoothpaste.net","subject":"Re: Revert and reset and very damaging Git commands","fromName":"Thomas Guyot","fromEmail":"tguyot@gmail.com","sentAt":"2022-07-11T23:20:36Z","receivedAt":"2022-07-11T23:20:43Z","isPatch":false,"sender":{"key":"tguyot@gmail.com","avatar":"https://avatars.githubusercontent.com/u/403890?v=4"},"body":"On 2022-07-11 17:40, brian m. carlson wrote:\n> On 2022-07-11 at 19:52:05, Gerriko io wrote:\n> Gosh this is not good.\n>> Why are these commands bypassing all the fundamentals of a computer\n>> OS. Surely if a file is deleted it should end up in the computer's\n>> rubbish bin. Not deleted permanently without a trace.\n> In general, the programmatic interfaces used to create and delete files\n> don't use the user trash can.  That's because many programs create and\n> delete extremely large numbers of temporary files (Git included) and it\n> would be silly to expose those to the user, since the user trash can is\n> designed to handle files that the user specifically might want to\n> recover.  There is also no standard portable interface for placing files\n> into the user trash can, while there are standard portable interfaces\n> for actually removing files.\n>\n> Also, traditionally, on Unix systems, deleting files has happened\n> without prompting, and Git is designed for Unix systems.\n\nI'd like to add that in only very few cases git will remove untracked \nfiles that haven't even been added to the index - for example git clean \n-f (-f is force), as it's designed to remove untracked files.\n\nIn the case of reset, it could effectively wipe untracked files but only \nif you reset to a revision that has these same paths, else it would not \ntouch untracked files at all.\n\nAdded files would however be affected but as pointed out earlier they \nare already in your object store and can be recovered using git fsck.\n\nIf unsure about a command, especially with a name like \"clean\" or \n\"reset\", all command are documented and the man page can be usually read \nusing:\n\ngit <command> --help\n\n--\nThomas\n"}]}