git-undo | Undo any git commands | Continuous Backup library
kandi X-RAY | git-undo Summary
kandi X-RAY | git-undo Summary
A wrapper around git that lets you undo unfortunate git commands by making backups of your git repository. Currently, you can undo the 5 most recent git commands.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Set up global settings .
- Backup files .
- redo the command to redo
- Undo the undo command .
- Undo the undo command .
- Get the last commit .
- Undo the last commit .
- Prompt user for confirmation .
- Returns the current commit .
- Moves the most recent flag to the last one .
git-undo Key Features
git-undo Examples and Code Snippets
Community Discussions
Trending Discussions on git-undo
QUESTION
I accidentally commited to branch dev
, instead of feature-branch
, and pushed to the remote. Based on the advice from git undo commit on protected branch?, I took the following steps to undo the commit on dev
and commit it to feature-branch
on dev
, undo the commit locally and stash it, so I can later commit it to feature-branch
:
git reset --soft HEAD~1
git restore --staged .
git stash
git pull
git revert SHA-1
git commit -m "reverting commit made to wrong branch"
git push
on feature-branch
:
git stash pop
git add .
,git commit -m "making commit in the right place"
Great. At this point, dev
is back to where it was before I wrongfully made the commit there, and feature-branch
has the new changes. I then did some more work and added more commits to feature-branch
.
After creating a pull request from feature-branch
to dev
and merging it in, it seems the commit that was reverted is not present on dev
.
What is happening here?
For now I will just create a new branch and manually rewrite the commit, but I don't comprehend why this series of events has led me to see a diff in my IDE (vscode and gitlens), but github is telling me there is no diff?
...ANSWER
Answered 2021-Dec-22 at 21:42tl;dr: It appears that you attempted two different solutions for the same problem, and ended up not doing what you think you did.
If you accidentally committed something to dev
, and wanted to fix it, you have two (categories of) ways to deal with it:
- You can
reset
back to the previous commit, essentially deleting the most recent commit. - You can
revert
the commit.
It's not clear whether you had pushed out dev
with the errant commit on it, but I suspect that you probably didn't, based on the description. In that case reset
would have been the best way to go. Had you already pushed the mistaken commit and others were likely using it already, then revert
would have been best. Apparently you tried to do both of these; it looks like you did a reset first followed by a revert.
The first reset "deleted" the commit, and then trying to revert something that isn't there wouldn't work, so you'd be left where you started. (Do you remember seeing any messages to this effect when you tried it?)
Note, had you previously pushed out dev
and decided revert was the way to go, after resetting back a commit you wouldn't have been able to do git push
without force pushing.
Side note, to move that commit over to feature-branch
, you can simply cherry-pick
that commit by the hash ID it had on dev
, instead of trying to go through the extra work of stashing it, which I suspect is what led you down this path to begin with.
Tip: I highly recommend using git log
or git log --graph
often. Consider using a UI that displays the branch history and refreshing it after every commit you make so you can see exactly what you're doing, and mistakes will become obvious.
QUESTION
Scenario:
- Created a Feature Branch From Master(Blue Color Branch)
- Made commits to it
- Later Merged with the Master and Deleted the Branch
- In between, I have created other Feature Branches and made commits to them.
Question: How can I get back the branch I deleted and unmerge so that the master looks clean without the Feature Branch (Blue Color)? I may need to add commits to that Feature Branch in future also.
I have looked at the following resources: Git undo local branch delete Git unmerge a branch
Do I need to do both of the above to get the desired result? Or do I want to create a new branch and revert the commits added in the Feature Branch and merge it?
I am completely confused and please redirect me to the right path. A sample Git Graph for the use-case is given below.
Note: There is no merge in between the Feature Branch (Blue).
...ANSWER
Answered 2020-May-24 at 06:54Simply undo all commits on the master branch till you get back to the merge commit (with the deleted branch).
As merging two brances is a commit too, you then can just undo that.
Note: You can also use git rebase
(more about that here) to move single commits you made to another branch if necessary
References:
- Another useful thread - removing a single commit
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install git-undo
You can use git-undo like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page