How to restore commit history before first release on Github - github

I have a repository where I made many commits in January. Fast forward to July, when I was tinkering with Git, I got to know about the Releases feature.
Since I had many major features to push, I decided to create a new release.
Now I need the January commits for showing to someone but there is no trace of them anywhere, neither in the Commits section nor in releases. It just shows 4 commits since this release
The commit history shows as if I started commiting to the repo from July only
Any help is appreciated.

Somehow, my entire history was stored not in branch but in a tag that I created when creating that release.
That's why even going too much deeper didn't reveal anythin since the commits were HEADless.
I noted the tag's hash and did
git checkout tag-hash // now no branch checked out
git checkout -b new-branch-name tag-hash // created new branch from that tag
And with this, my new branch has the whole commit history

Related

Pulling From Developer Branch When Master Isn't Used And Push To Production Comes From Developer's Branch

For a project with multiple developers where one developer controls what goes to production: This developer pushes from his own branch <his_branch>, and everyone has to incorporate their changes into his branch. His branch contains his changes and the changes other developers' changes. How do I make sure I pull down his most recent branch and work from it on my local. I have tried so many different commands and approaches, with the most recent being:
Git clone the repository (done when I started the project)
Fetch his branch
Create a working branch <my_branch> from <his_branch>
git checkout -b my_branch origin/his_branch
(I get errors)
Create my branch on remote
Fetch all including my new branch (but my new branch contains code from Master)
Access my branch locally, work on it, commit changes, create a pull request for him to review
(I don't have his latest code) and there are many conflicts to resolve
I am new to GitHub and can't find a fairly straightforward answer to this question. Typically people who answer this question, make sure they provide the most complicated solution to follow to try to impress with their GitHub acumen.
Can someone provide a straightforward answer without snark, condescension, or derision?

Rebase master to upstream

I have a fork of microsoft/vscode-arduino on github. Some time ago I submitted a PR that was accepted. Time passed and now I want to do some more work.
At the time my use of git and github weren't very sophisticated and I rather foolishly did all the work on master.
On my local repo I pulled from upstream master, merged and committed to my fork, and was surprised to find that github thinks my fork is still 7 commits ahead and 113 behind.
Then I tried to rebase on the upstream as described on this page My pull request has been merged, what to do next? but the command
git pull --rebase origin master
and after a bit of mucking about I'm no commits behind and 12 commits ahead.
I really don't care about preserving anything. Everything important has long since been merged into the upstream repo. I just want to make this main exactly the same as current main in the upstream, so I can branch for my new efforts fixing an ongoing problem where every time there's a release of VS Code that uses a different version of node it breaks the serial port native integration until the Arduino extension is updated to the same release of Node and released.
Can anyone advise on how to do that? (discard the 12 commits ahead, not the N-API thing)
This may not be the most elegant but it worked.
Use GitLens in VS Code to find the oldest commit that isn't mine and do a hard reset to that.
In the terminal pane, git push --force. Refreshing the github page it now says I'm two commits behind origin (the repo I forked). I'm rid of the unwanted commits. Now to work forward.
In VS Code terminal pane git pull --rebase upstream master
In VS Code click on the status bar to sync.
Refresh the github web page. Hooray, This branch is even with microsoft:master.

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.

GitHub fork a repo from previous commit

I've found a repository on GitHub I would like to fork - but not the current version.
I want to fork the repo as it was quite a few commits back - is this possible? The repo has not marked any releases, so I'm not sure how to do this. I could obviously copy the code as it was in that commit, but I would prefer to fork, as then I get the link back to the original repo.
You can only fork the current repository.
You can reset the forked repository's master branch to an earlier commit though, making it look like as if you had forked it at that point.
See: How can I rollback a github repository to a specific commit?
If you reset every branch, it effectively resets your repository to an earlier state of the original repository (with exception of branch-independent data, like configuration, hooks etc which are not reset). Since it's possible that not all branches contain the commit from the master branch, you might need to look up commits by date for each branch, to reset them to the last commit before the commit from which you want to fork.
I was also unable to do this using github, but Sourcetree handled it perfectly.
Switched to the desired branch.
Found the commit that I wanted as the head of my new branch and right clicked.
Selected "branch."
My commit was already selected.
Name this new branch, create, and push.
Can also be done by selecting the "branch" button.
You then select the commit that you want as your new head, give it a name, and create it.

How to you rebase a GitHub fork?

There is a project on GitHub that I have forked. My workflow involves cloning my fork to my local machine.
Occassionally I commit my changes to my local branch. And eventually I push those changes to my fork on GitHub. I do this so I can work on my project at work, push my changes, then go home, pull the latest from my fork and continue working.
At this point, on my branch, I have several commits. I want to link my changes to some people for code reviews, but when I view an individual commit, it's diff is only compared to the previous commit from me. I don't want my peers to have to sift through all my commits trying to understand what changed from the beginning.
Is it possible to specify exactly which commit you are diffing against? In my case, I want to diff my latest commit against the latest commit in the origin branch.
If not, is there a way to rebase a fork on GitHub so that it combines my selected commits into one commit?
In most git based code reviews, it's normal practice to go through and review every commit and comment separately for each one. This is normally to help enforce good coding practices in terms of commit size and scope and testability.
In the command line, almost all commands support a revision interval as an argument
git diff <some commit>..<some other commit>
git log <some commit>..<some other commit>
and that will give you the results for changes solely within that range
also there is a difference between
git diff <some commit>..<some other commit>
and
git diff <some commit>...<some other commit>
as the third dot means inclusive, also showing results for which defaults to HEAD
In the github web client I don't think you can do this, I just checked their native client and it's a no go as well.
I did just look at Atlassian/bitbucket's SourceTree and that allows you to shift-select a range of commits as you're expecting