The same holds if you’re the only developer in your repo since you’re in full control of your own work and won’t interfere with anyone else. As for your own branches, you are free to do whatever you want-like deleting old commits you introduced on that branch. But there are also the so-called “personal” (feature) branches that individual developers create and commit to directly, and that later get merged into milestone branches (or directly into your master branch, depending on your workflow).Įverything you’ll learn in this tutorial is still practical and can be extended to the real world, so long as you keep in mind that you should never try to undo changes in git on public branches, unless you know what you’re doing. These branches provide an untouched history of your repository, documenting your features and software releases. Public branches like master are ones that your team regularly merges work into via pull requests and that nobody commits to directly. With git tutorials, it’s often difficult to accurately simulate the real world, where you most likely will not be committing directly to master, and where you’ll be working with other developers. env to git, good eye! We’ll delete that later.) A Note on Modifying Public Branchesįor me to come up with reproducible code samples for this tutorial-and for you to be able to easily run them on your end-we’ll be executing most git commands directly on master itself. (Also, if you’re concerned that we added an. Obviously, your commit hashes will differ from mine.įeel free to follow along and run these commands-the best way to learn git is to use git! * 0beebfb - Add package.json (5 seconds ago) On my end, that gives me this history: * 4753e23 - (HEAD -> master) Add. & git commit -m "Add package.json" & \ echo FOO =bar >. For now, however, it’s always nice to continue to refine my understanding of the differences between reset and revert (which I’ve written about here and here before) and now add a new arrow to the quiver in the form of restore.Before we get to the examples, let’s create a simple git repo with a few commits: git init & \ echo > package.json & git add. Restore is significantly more powerful than the basic example shown here and I intend to continue to explore different methods of leveraging its power in time. " to include in what will be committed)įor what it’s worth, gsdf would also not work for this file for the exact same reason: Git doesn’t know about it! Wrap Up Modified: notes/git-reset-vs-revert-redux.md ![]() " to discard changes in working directory) (use "git push" to publish your local commits) Your branch is ahead of 'origin/master' by 1 commit. Looking at our current status we can get our bearings: Now, however, this outcome is built directly into Git in the form of the restore command. In the past I’ve used a custom bash function, gsdf (an abbreviation for “git stash, drop file”) for this purpose. Imagine making some changes to your branch for some temporary edits, but now you want to get back to the original state of the branch. Let’s consider an example of when you’d want to use restore instead of revert or reset. Notice that revert and reset are history altering (making a new commit in former, and moving the tip in the latter), where as restore does not modify history. Git reset can also be used to restore the index, overlapping with git restore. This operation changes the commit history. Git-reset is about updating your branch, moving the tip in order to add or remove commits from the branch. The command can also be used to restore files in the index from another commit. ![]() This command does not update your branch. Git-restore is about restoring files in the working tree from either the index or another commit. Git-revert is about making a new commit that reverts the changes made by other commits. ![]() There are three commands with similar names: git reset, git restore and git revert. From the documentation, Reset, restore and revert: Similarly to Git’s reset and revert commands, restore is a way to update the working tree’s files. The restore command for Git is still experimental, but is a more intuitive solution to some of the problems I’ve come across regularly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |