![]() Maybe you don’t know that there is a flag that while undoing a commit with git reset, it allows you to keep the commit changes on staging and the commit message stored in a special variable that I’ll show you in a bit. Given this scenario, the first step is to use the command git reset. You want to undo this commit and redo it to the correct branch.Īs an example, I have here a history of a project in which there are two commits: the initial commit on the main branch ( d815be) and the second commit ( 5e8ae2) adding arquivo-1.txt that should be on another branch, see:.You haven’t pushed this new commit to the remote yet.Let’s say we then decide to revert to the first commit in the repository. ![]() With that, let’s assume you’re in the following situation (interestingly I went through this last Friday): echo 'Text to be committed' > testfile git add testfile touch newtestfile git add newtestfile git commit -m 'More text added to testfile, added newtestfile'. The most basic use of this command is to use it to undo one or more of the most recent commits. In a nutshell, it is a command that allows you to return to a previous state. I talked about the command git reset in this other pro tip. ![]() With these two commands in your repertoire of Git commands, you will be way happier. Reuse the content of the undone commit to make a new commit.Undo the last commit so you can keep the changes on staging.In this pro tip I will teach you how to do two things: Undoing and redoing commits is part of everyday life, so it’s important to understand the commands that can help us along the way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |