'Reset current branch to this commit' not working for unpushed commits in Sourcetree - version-control

When I unpushed commit(counts 3 on the Push button) use Reset current branch to this commit and choose Hard. I got this(6 Pull, 2 Push in UI like in the photo) and on retry it's still the same. How do I fix it?

Related

Undoing Git Branch Commit and Merge

I'm currently working on an assignment where we work on a local repository and push to a remote repository when we are done. We are expected to make use of branches, wherein we make all our commits before merging it into our master branch, so no commits directly to the master branch.
Everything was going fine, but I've come across a problem when I made some commits on a branch, then merged that branch into my master, before going back to the before-mentioned branch to make some more changes, committing them and merging it once again back into my master branch.
My network tree is currently looking like this:
network branch
The problem being the green branch that is branching off at the end with hash 2bbbd0c.
I'm essentially looking to undo that commit completely and simply have my branch merge into my master, so my network branch shows that nothing is branching off.
One idea I have is to use git reset –hard 2b32611 (which is the hash for my latest commit on the branch before merging it into my master):
enter image description here
And then to use git push -f origin 2b32611:cookies-user-tracking to push the commit and the branch, but once again I’m not sure if that’ll work, and I don’t want to mess anything up.
The git reset --hard will indeed reset cookies-user-tracking to the right commit (before merge)
All you need to do then is to force push the branch:
git push -f origin cookies-user-tracking

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 :)

GitHub: Commit a point in history as the head of master

There is a certain commit I did to my Git repository which I host in GitHub. After that commit I've made several other commits, which were bad and redundant, in a second look. I thus need to revert to the certain commit / certain point in history before these bad changes.
I didn't find a button like "revert to this version" or "commit this version as the head of this branch (master)".
As you can see, I just want to make that older version the head of the master branch. How will you do that from GitHub?
Update
I emphasize: I ask on GitHub, not on git or any GUI other than GitHub.
If I understand you correctly you want a past commit as the last commit on the branch.
If so, using examples with origin and master:
Use git reset <comit_id> and then git push origin +master to push & delete all commits past the one you reset to. Notice the + sign before the branch name (master).
Note that this is irreversible (as far as I know) so take the necessary precautions.

Restore branch deleted from GitHub

I had a branch on a GitHub project that I merged into master. I then clicked the 'delete branch' button on GitHub, and thought I was all set.
Turns out I wasn't, and I want to restore/reactivate the branch. I did not delete the branch on my local respository, nor did I run any git fetch/pull afterward. Just clicked the delete button on GitHub.
Wanted to sound out what a good next step should be. Thinking of doing git push from my local box but wasn't sure what the repercussions might be, would the remote repo on GitHub squawk about a dead branch being brought back, etc.
If you didn't remove your branch from your local machine, and you got rights to push to GitHub, you can restore it on Github by pushing it again
git checkout localBranchName
git push origin localBranchName
It doesn't matter if you make a fetch from Github, git wont remove your local branch until you explicitly tell it to do so with
git branch -D localBranchName
In fact, even if you had removed your local branch, if you merged it previously with master, you can restore it locally. You have to go to the last commit, prior to the merge and branch from there. Something like this for example:
git checkout master
git checkout -b localBranchName
git reset --hard HEAD~1 ( 1 is the number of commits you want to undo )
The second command will create a new branch pointing to your last commit on master
The third command will the last commit undoing (only on that branch ) the merge with master.
Another thing you can do is use "git reflog". That command is very usefull since it will show each time you moved between branches and/or commits.
Go to your list of commits. Find the commit with the merge and click on the pull request number (the number prefixed with #). This will direct you to a page with info about the merge and a button with the label 'Restore branch'. Click that and it is restored.
It looks like there is a "Restore branch" button now that shows up in place of the "Delete branch"

gitHub - Committing and Pushing Dev Branch Pushed to Another Branch

I have a dev branch. I made local changes, committed them git commit -m "blah" file and pushed these changes to my branch(ccap-biology-dev) git push origin ccap-biology-dev
. These changes were committed another branch(ccap-biology) as well as some temp files that my .gitignore file handles. None of these temp files are on my branch. I would like to avoid this from happening again. However, I do not know what I did incorrectly or the best way to correct this.
Steps I've taken to attempt to isolate the problem:
1. git remote -v:
origin https://github.com/Connexions/oer.exports.git (fetch)
origin https://github.com/Connexions/oer.exports.git (push)</code>
2. git branch -avvv
ccap-biology 0105488 [origin/ccap-biology] Update css/ccap-numbering.less
* ccap-biology-dev c674100 module2epub
remotes/origin/HEAD -> origin/master
remotes/origin/ccap-biology 0105488 Update css/ccap-numbering.less
remotes/origin/ccap-biology-dev c674100 module2epub
remotes/origin/master fa3d5fa Added some styling to solutions
3. branch log file doesn't reflect a commit on ccap-biology
4. gitHub Activity Feed does not show this push either
This happen during commit c674100 module2epub. What are the next steps to take to find out what happened? What is the best way to cleanup the branch that I accidentally pushed to?
Any help appreciated. Thanks ahead of time.