You can use the git checkout command to undo changes you’ve made to a file in your working directory. Undoing Local Changes That Have Not Been Committed In your terminal (Terminal, Git Bash, or Windows Command Prompt), navigate to the folder for your Git repo. Git checkout -force BRANCH-NAME Undo Changes in your Working Directory ![]() When you run the following command, Git will ignore unmerged entries: git checkout -f BRANCH-NAME Basically, it can be used to throw away local changes. You can pass the -f or -force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD). This is equivalent to running git branch with -f. If the BRANCH-NAME branch already exists, then Git resets the branch to START-POINT. If the BRANCH-NAME branch doesn’t exist, Git will create it and start it at START-POINT. The following command is similar to checking out a new branch, but uses the -B (note the captital B) flag and an optional START-POINT parameter: git checkout -B BRANCH-NAME START-POINT Checkout a New Branch or Reset a Branch to a Start Point This will automatically switch you to the new branch. To create and checkout out a new branch with a single command, you can use: git checkout -b NEW-BRANCH-NAME You have three options to handle your changes: 1) trash them, 2) commit them, or 3) stash them. Generally, Git won’t let you checkout another branch unless your working directory is clean, because you would lose any working directory changes that aren’t committed. ![]() To checkout an existing branch, run the command: git checkout BRANCH-NAME We can get the specific commit id’s by running: git log Checkout an Existing Branch To checkout a specific commit, run the command : git checkout specific-commit-id There are a number of different options for this command that won’t be covered here, but you can take a look at all of them in the Git documentation. ![]() The git checkout command switches between branches or restores working tree files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |