Git Rebase Interactive - github

I'm trying to delete old github commits with the interactive rebase, but I don't know how to actually save the changes I've made and push them onto my repository. I haven't found anywhere that actually explains how to exit the interactive rebase, and keep your changes. Help?

You just need to finish the rebase instructions in your editor.
Exit your editor, and it should apply your changes.
If there are any conflicts while rebasing, you'll have to fix them, stage your changes and use git rebase --continue.
That's it. The rebase will finish itself.
Once you're done, you'll have to force push to overwrite the remote state of your branch.

Related

Cancel undo commit VSCode

Accidentally I press Undo Commit and all my work dissappeared, Is there any way to revert it?
I didn't commit my last changes and that is the work I lost
As mentioned here, VSCode "Undo Last Commit" runs git reset HEAD~.
That means you can restore your last commit (but not easily your work in progress at the time of the undo) using git reflog, and a git reset --hard <lastSHA1> (again, make sure you don't have a work in progress, use git stash if needed).
However, for any work in progress, you will need the VSCode local history as mentioned in the comments.

How to undo the last commit on GitHub?

I want to undo the last commit pushed to GitHub on the master branch of a repository, and make it so that it's as if this commit never existed and doesn't appear in the commit history.
How do I go about this?
Note to those voting to close — the proposed alternative questions are needlessly complex, have condescending answers, and are littered with giant walls of text that are difficult to sift through.
Hence, this simple question with a simple answer for my benefit and that of posterity.
I think you're looking for the --force argument.
You can reset to a specific commit with git reset --hard {commit sha} and then force the change to origin with git push --force.
Note that if others are using your repo, they will need to use git pull --force or they may inadvertently put your unwanted commit back into the repo.
I recommend reading the help documentation for git reset and git push before taking action.
If you wish to rewind the master branch of the repository to a previous pushed commit, simply run this command — of course, with the appropriate commit hash:
git reset --hard a0b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9
git push --force
This may have unintended consequences if, for instance, there are collaborators on your repository. But, I am sure you know what you're doing 😉

I am trying to go back to a specific commit in Github to erase the mistake I made

I have looked at many past posts without a specific response. I used git reset --hard to get me to a point in time when my code was not all jacked up. Yes I should have used a branch but I didn't. Now I have a message of HEAD is now at 0600b73 fixed error. What I would like to know is how to commit those changes, so I can push them back to Git, so they are the current head? I am not even sure if VS Code even recorded the changes. Git can be confusing so any help would be appreciated.
You haven't actually proven you have changes, HEAD is now at 0600b73 fixed error., that does not mean you have changes. That basically means that you moved the HEAD of git to a commit, generally you want it on a branch.
git status will tell you if you have things that need to be committed.
I am not even sure if VS Code even recorded the changes
VScode has some cool features around git but it doesn't actually record changes, unless you are referring to saving files. If you save the file, well it saves.
What you probably want to do is (I am assuming you actually do have changes):
confirm you have changes git status
move to a branch git checkout -b my-fix
add those changes git add . (adds all changes/also make sure you are at the root of the repo) or git add -p will let you look closely at changes and give you an interface to decide if you want to stage the change or not.
commit the changes git commit -m "Your message" or you can do a longer message with git commit -p
At this point you can merge this branch in to master, push the branch. It's up to you.
push your changes, git push origin my-fix, make a pull request and merge to master. You will then want to change to master and pull master
merge git checkout master , git merge my-fix
rebase git checkout master , git rebase my-fix
Here is some git learning material:
https://learngitbranching.js.org/
https://www.codecademy.com/learn/learn-git
https://try.github.io/
https://www.atlassian.com/git

How to revert a pull request commit on GitHub

I am trying to revert my latest commit on GitHub. All the information I have looked through says that there should be a revert button in the pull request but I do not see it, and cannot find it.
Is there anyway to do this on GitHub? Or could I do it terminal with a few rebase commands?
Assuming this pull request merge is a commit merge (what I would expect), then you may try the following from the Git bash:
git checkout your_branch
git revert <hash of merge commit> -m 1
git push origin your_branch
This solution assumes that you want to revert back to the branch into which the pull request merge was made. If you want to follow the incoming branch, then use -m 2 instead.
To find the SHA-1 hash of the merge commit, you may use git log, and then copy over the hash from the first commit, which should appear at the top.
Note that nuking the merge commit and then doing a force push is generally a bad idea here. The reason it is bad is because your branch is published on GitHub. This means that rewriting the history of that branch could cause problems for anyone besides you who happens to be sharing this branch.
In android studio click version control tab in the bottom. Then click log
Then your all the commits will be visible. Then right click on relvent commit and revert it.
Then commit changes and push again.
Get the hash of the commit in which you want to revert back. Then do:
git checkout 54722c31619b0662b379923d0be4b8f8f1f125c9
The long number you are seeing is the hash of that particular commit in which you want to revert back.
Then force push into the branch you want to revert back.
git push origin <your_branch_name> --force
I hope this helps. Happy coding :)

How to undo a Git rollback

I wanted to rollback to the last commit after making a massive error, but I managed to rollback a little too fair. The commit I wanted to reassert doesn't appear when I enter 'git log' in bash (I suppose because it's no longer in the history). Is there any way I can recover the last commit by date?
I'm also using eGit in eclipse for the same project if that makes things easier. Thanks.
If you are ok with command line, go to you repo, do a git reflog and get the commit which you want to "rollback" to and do a git reset --hard <commit>
You would also be able to do git reset --hard HEAD#{1} and then come back to egit and rollback to the desired commit.
I find that generally it's better to make your changes forward in time rather than backward.
Git's approach is to "revert" the commit. When you revert a commit, you check out into your working directory the inverse of the commit in question. Then you add and commit that, and you've just made a NEW commit, that commits the "undoing" of the commit you're reverting, AND it leaves a record in history that such a thing happened, so if you want to undo your undoing, it's easy to do.