$ git commit -m “Added text file – Commit 2”
GIT CREATE BRANCH FROM LAST COMMIT HOW TO
If you refresh you remote repo, it should display the locally created branch and a text file with the commit message.įor learning how to undo commits in Git, I have created two more text files (tst2.txt and tst3.txt) on local repo and executed the commit commands as follows: Pushing these changes to the remote repository: The above graphic shows all these commands and output messages on Git Bash.
This command is executed so we may add files in this branch.Īfter creating tst1.txt file in the local folder, execute the add command for adding a file in demo1 branch: (downloading any content in the remote repository to the local)Ĭreating the first local branch where we will commit three times and undo the committing to level 1 and 3 later. (For initializing the empty git repository locally)įor synchronizing the remote repo with local. So, quickly these commands are executed until our first commit: Most probably, you already know about all that, this is just for beginners (others may skip to next heading below). Fast forward, I ran a few commands as shown in the graphic below – for synchronizing the remote branch with local, creating a new branch locally and started adding files: The remote repository is created on Github and local on a Window system.īy right clicking on the local system folder, I opened the Git Bash ( as explained in this tutorial). To understand the undo process by using Git restart with –hard and –soft flags, let us start with the basics.įor the demo, I have created a remote and local repository. Still unclear, let us go through adding files in a branch, committing the changes and then doing hard and soft operations for undoing changes in the example below. You will see, the changes in the last commit are preserved, however, the HEAD pointer is moved back to the previous position. If you run this command after the above command:
For that, you may use the –soft in reset command as used below: So, for example, you do not want to discard changes made: files added, or any other changes. The other two are:īy using the –soft flag, you may keep the changes in the last commit while moving the HEAD pointer back to the last commit. The one is used in the above command i.e. Keeping the changes in previous commit exampleīasically, the reset command has three forms of invocation. So, your last commit is undone and any files added or changes made are removed. This command will make the Git move the pointer of HEAD back to the previous commit.