8/11/2023 0 Comments Git reset originIf we do an ‘ls’ now, it looks like this: Mode LastWriteTime Length NameĪnd, our git log now shows only 3 commits, with head now pointing to the commit where network.tf was added: $ git log -oneline Again, just to stress this can have a significant impact, so be careful to ensure you understand what the result of the reset will be! Any untracked files or directories in the way of writing any tracked files are simply deleted. Any changes to tracked files in the working tree since the commit are discarded. In this case I want to go back to where I added network.tf but before I added storage.tf, and made those other changes: $ git reset bcf4be1 -hardĪ –hard reset resets the index and working tree. We do this by using the git reset command to move the head back to an earlier commit. We can reset the git branch to an earlier point in time. ![]() Now, during testing, these code updates didn’t work out as expected, and I need to go back to how things were when I made the network.tf commit. Ok, so lets say we were developing these files locally, and after the latest commit I made some changes to the network.tf file and add a new database.tf as well. $ git log -onelineĢ37adf8 (origin/main, origin/HEAD) first commit Note: Before you perform a git reset you will first need to check the git log so that you can get a list of all the previous commits in your git branch. We can see this commit history by checking the git log. I went through this a couple of times to build up a commit history for the purposes of this demo. These are the commands I used to create the new file then commit them: $ echo "#network tf" > network.tf This mimics common activities if I were working on developing a Terraform plan. For my first commit I will create a new file called network.tf, then follow that commit by adding another file called storage.tf. Ok, so next we need to make a couple of changes and commits to this git branch. So the first thing I want to do is to clone the remote repository so that I can work with it locally: $ git clone :buildvirtual-git/test-repo.gitĪ quick directory listing using the ls command shows that the repo has been cloned successfully and that we have a copy of the project files in a local directory: $ ls
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |