I am new to git and github and I have some trouble.
I am using github for windows to manage a small project I have. I think I've lost some changes I recently did to my code. What I did was:
Now all changes are gone, including some new files I added. Can I save them? I have also installed git (command line) so I can execute any command you think will help.
To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.
With GitLens installed, open your repo in VS Code and right-click on the commit from the Commits view in the sidebar to get the Revert Commit option. You can also access this option through the command palette by typing >GitLens: Git Revert or from the commit details' quick pick menu.
The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified.
One of the nice things about git is that it's REALLY hard to lose anything, unless you're doing something weird.
What you need to do is to find the point which represents the state at which you want to be.
Let's say you examine git log and determine that hash 01dbc4... is the point in time to which you want to return. To do so, simply do:
git reset --hard 01dbc4
Note that if you have uncommitted changes, you'll need to stash them first.
Now, if that commit is missing the extra files you want and they're in a later commit, it gets a bit more complicated. But what you can do is set your master branch to the point from which you want to start, and then set a branch to the point which has the new files. You can then copy or or selectively merge the missing information from the new branch to your master branch, making your master branch look how you want it.
Note that even if you move a branch's pointer around like when using git reset --hard above and orphaned later commits, you get them back by examining git reflog
and reseting to them, or creating a branch that points to them.
Note that now (March 2013), with GitHub for Windows, you can undo a commit without having to type any git command:
See "Undo Button in GitHub for Windows"
we've added Undo support for Discards, Commits, Rollbacks, and Merges:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With