From eabf6386ea9cf71270307c0e786cb2a232e07e45 Mon Sep 17 00:00:00 2001 From: Ashish Ranjan Date: Sun, 28 Jul 2019 00:11:51 +0530 Subject: [PATCH] fix(setup): Remove step to hard reset this repo This is a slightly embarassing story, but needs to be told for context. When I was creating my `dotfiles` repo, I copied the `initialize_git_repository.sh` from this repo. It worked as following: - Initialize git at the root of this project, if this is not a git repo - Add an origin URL as remote - Fetch the changes from origin/master - Run `git reset --hard origin/master` to mirror origin/master I created all the other files and tested it locally. More than 70% of my final work was done. And, then I ran the `setup.sh` script which called `initialize_git_repository.sh`. Since, I had not even initialized git in the repo (and thereby had not committed any changes), it ran all the above steps. As a result, I lost all my changes from the past more than 6 hours in under 5 seconds. It was devastating, to say the least. So, I'm removing the final step to hard reset because this could easily be weaponified to delete all the files on a computer. The user must run `git reset --hard` herself to be in full control. However one positive things came out out this and I learnt an important lesson. > Always backup your data, even when you don't! --- src/os/initialize_git_repository.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/os/initialize_git_repository.sh b/src/os/initialize_git_repository.sh index 121ce8e..b246080 100755 --- a/src/os/initialize_git_repository.sh +++ b/src/os/initialize_git_repository.sh @@ -39,9 +39,7 @@ update_git_repository() { declare -r remote="$1" declare -r branch="$2" - execute \ - "git fetch $remote $branch \ - && git reset --hard $remote/$branch" \ + execute "git fetch $remote $branch" \ "Update the Git repository" }