12/26/2023 0 Comments Undo local commit![]() ![]() Sometimes the manual approach is not easy to achieve, or you want to revert a specific commit (ie not the previous one on your branch). Next, you apply the changes by hand, or you can run this command (which effectively removes the last line of the file) to achieve the same result in this particular context only: head -9 file > file2Īnd then commit the change: git commit -am 'Revert C10 manually' If you haven’t done any funny business on your repo then it points to the last commit on the branch you are working on. The HEAD tag always points to a specific commit. The output should show you a diff of what changed in the last entry. The ‘ git show‘ command can give you this: git show HEAD ![]() The simplest way (conceptually, at least) to undo a change is to add a new commit that just reverses the change you last made.įirst, you need to see exactly what the change was. See here if you want to know more about this git log command. If you run: git log -oneline -graph -allĪt any point in this walkthrough you should be able to see what’s going on. Now you are in a fresh folder with a git repository that has 10 simple changes to a single file (called ‘ file') in it. If you want to follow along, run these commands to set up a simple series of changes to a git repository: cd $(mktemp -d) There’s many ways to achieve the result you might want, so this can be a pretty instructive and fertile question to answer. This got me thinking, and I came up with a walkthrough similar to the ones I use in my book to help embed key Git concepts and principles. Recently, while showing someone at work a useful Git ‘trick’, I was asked “how many ways are there to undo a bad change in Git?”. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |