![]() Git reset -hard HEAD~1 # hard reset 1 commit behind (deletes local commit) Git pull # bring your local in sync with remote Git stash # hold your work temporary storage temporarily. Quick Answer git reset -soft HEAD~1 # 1 represents only last 1 commit Here's a clean way of removing your commits from the remote repository without losing your work. Preserved but not marked for commit) and reports what has not been Resets the index but not the working tree (i.e., the changed files are If you don't use -hard nor -soft, the default mode is used that is -mixed. If you use -hard option, git status will tell you that your local branch is exactly the same as the remote one. In the latter case runnig git status shows the files changed since. Then you have chance to check your latest changes and keep or drop all or parts of them. ![]() ![]() If you want to keep changes on file system and just modify index (commit history), use -soft flag like git reset -soft HEAD~3. Then you can replace HEAD~N with like this: git reset -hard You can retrieve the desired commit id by running git log Then run the following command (on your local machine) to force the remote branch to rewrite its history: git push -force If you want to delete for example the last 3 commits, run the following command to remove the changes from the file system (working tree) and commit history (index) on your local branch: git reset -hard HEAD~3 This is a convenient shortcut for: $ git branch -f Similar to -create except that if already exists, it will be reset to. That will restore the index and working tree, like a git reset -hard would. (replace n by the number of commits to remove) That is: git switch -C mybranch origin/mybranch~n ![]() With Git 2.23 (August 2019, nine years later), you would use the new command git switch. Plus, as noted by ringo in the comments, if the remote branch is protected against force push, a git revert, as in this answer, might be preferable. You need to be prepared to point out people to the RECOVERING FROM UPSTREAM REBASE section of the git rebase man page. This SO answer illustrates the danger of such a command, especially if people depends on the remote history for their own local repos. ( other solution here, involving deleting the remote branch, and re-pushing it) You git reset -hard your local branch to remove changes from working tree and index, and you git push -force (or git push -force-with-lease) your revised local branch to the remote. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |