11/2/2023 0 Comments Discard changes git command lineHowever, having a flow can also unintentionally make you cut corners, for example forgetting to switch to a topic branch before doing all the work, leaving your newly crafted solution hanging in the wrong branch.Ĭonsider the illustration below, where two commits have been committed to master (since it was last synched), when in fact the desired outcome was to do the work on a separate topic branch! As none of the local commits ( C1 & C2) have yet been pushed, solving this problem is work for reset. Restoring changes from the Staging Area doesn't infer any loss of data, while restoring changes in the Working Tree might discard data completely.Ī cautionary warning: Whenever you restore a file inside your Working Tree, do note that this is a destructive operation leading to potential loss of data! □Removing commits from a branch (reset)īeing on a development streak (aka having a flow) is a highly appreciated feeling, typically appearing when you know exactly what to do and only need to translate your internal thought-out solution into code. Here the Staging Area is displaying any changes made related to HEAD, while the Working Tree displays changes related to the Staging Area. On the other hand, restoring changes made to the Working Tree would ultimately discard them completely. Performing restore on the staged changes would only undo what's about to be committed and not infer any loss of data, as the change itself is also present in the Working Tree (notice the "bar" line in index.js). Take a look at the below example illustrating a dirty Working Tree including changes staged for commit. And just like the official documentation states, restore doesn't update your branch (i.e. If, and when, that happens, restore is your weapon of choice.Īlthough restore has a multitude of use cases, in its simplest form it's used to remove changes from the Staging Area, or to discard changes made to your Working Tree. Not doing so might cause you to add files by accident which you don't want to commit. isn't something I'd recommend doing, as it's generally better to be more selective in what files to stage. ➕ Removing an accidentally staged file (restore) With the general command description from above top of mind, let's see how they differ in reality. Ok, still not crystal clear? Let's contextualize the above statements and solve our initial problems using them. " revert is about making a new commit that reverts the changes made by other commits.".The command can also be used to restore files in the index from another commit." This command does not update your branch. ![]() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |