![]() Note: git checkout also has a patch mode that does exactly the same as git restore’s patch mode, but the key here is that using the git restore command to restore a file to its previously committed state is both more memorable and semantically correct. Pretty overwhelming… The best place to start is with y (‘yes, discard this hunk’) and n (‘no, don’t discard this hunk’), leaving things like splitting hunks for another day, once you’re more familiar with it all. S - split the current hunk into smaller hunkse - manually edit the current hunk A -mixed reset will move any pending changes from the staging index back into the working. K - leave this hunk undecided, see previous hunk Git reset is primarily used to undo the staging index changes. K - leave this hunk undecided, see previous undecided hunk J - leave this hunk undecided, see next hunk ![]() J - leave this hunk undecided, see next undecided hunk search for a hunk matching the given regex This guide looks at some of the most common use cases, including discarding changes to staged, unstaged, and untracked files. Q - quit do not discard this hunk or any of the remaining onesĪ - discard this hunk and all later hunks in the fileĭ - do not discard this hunk or any of the later hunks in the file 1 min read Git has plenty of different ways to let you discard your local, uncommitted changes depending on the status of files in your project. N - do not discard this hunk from worktree In case you’re not sure what any of those mean (a situation I find myself in all the time!), typing ? and hitting enter gives you a nice reference: y - discard this hunk from worktree Once we’re in patch mode, we just need to work our way through the changes by typing a letter from the multitude of options: Discard this hunk from worktree ? Reverting means undoing the changes by creating a new commit. The following command would enter patch mode for every file we’ve edited since our last commit: git restore -pĪlternatively, we can restore parts of a specific file with: git restore -p path/to/file.html If you have a commit that has been pushed into the remote branch, you need to revert it. Just like git add’s patch mode, we don’t have to use the full -patch flag we get a handy -p shortcut. I really like git restore, and one of its superpowers is its patch mode, where we can restore parts (or ‘hunks’) of a file, rather than the whole file at once. to discard changes in working directory) modified: CONTRIBUTING.md It tells you pretty explicitly how to discard the changes you’ve made.
0 Comments
Leave a Reply. |