Reputation: 26772
I need to download the Facebook API from GitHub. Normally, I just click on the 'Downloads" tab to download the latest source code. In this case, I need an older commit: 91f256424531030a454548693c3a6ca49ca3f35a, but I have no idea how to get the entire project from that commit...
Can someone please tell me how to do this?
(BTW, im on a mac. Don't know if that makes any difference).
Upvotes: 220
Views: 394548
Reputation: 11
git reset --soft
git reset --hard **reset all code to particular commit and delete current uncommitted code
Upvotes: 0
Reputation: 31
To use the Github webpage to do this, here's what I did exactly: go to the commit list -> click the commit number I need to download -> click "Browse Files" on the upper-right of the page -> click the dropdown button "Code" and then click "Download ZIP".
I don't have git terminal and don't want to set up one only for downloading a commit, Sivanand Kheti'S answer helped me to download the commit using webpage browsing, and hope my steps help the same users as myself.
Upvotes: 1
Reputation: 167
write this to see your commits
git log --oneline
copy the name of the commit you want to go back to. then write:
git checkout "name of the commit"
when you do this, the files of that commit will be replaced with your current files. then you can do whatever you want to these and once you're done, you can write the following command to extract the current files into another newly created branch so whatever you make doesn't have any danger for the previous branch that you extracted a commit from
git checkout -b "name of a branch to extract the files to"
right now, you have the content of a specified commit, into another branch .
Upvotes: 0
Reputation: 1127
Try the following command sequence:
$ git fetch origin <copy/past commit sha1 here>
$ git checkout FETCH_HEAD
$ git push origin master
Upvotes: 11
Reputation: 6299
Instead of navigating through the commits, you can also hit the y key (Github Help, Keyboard Shortcuts) to get the "permalink" for the current revision / commit.
This will change the URL from https://github.com/<user>/<repository>
(master / HEAD) to https://github.com/<user>/<repository>/tree/<commit id>
.
In order to download the specific commit, you'll need to reload the page from that URL, so the Clone or Download
button will point to the "snapshot" https://github.com/<user>/<repository>/archive/<commit id>.zip
instead of the latest https://github.com/<user>/<repository>/archive/master.zip
.
Upvotes: 5
Reputation: 173
The question title is ambiguous.
Upvotes: 5
Reputation: 2557
As addition to the accepted answer:
To see the hashes you need to use the suggested command "git checkout hash", you can use git log
. Hoewever, depending on what you need, there is an easier way than copy/pasting hashes.
You can use git log --oneline
to read many commit messages in a more compressed format.
Lets say you see this a one-line list of the commits with minimal information and only partly visible hashes:
hash111 (HEAD -> master, origin/master, origin/HEAD)
hash222 last commit
hash333 I want this one
hash444 did something
....
If you want last commit
, you can use git checkout master^
. The ^
gives you the commit before the master. So hash222
.
If you want the n-th last commit, you can use git checkout master~n
. For example, using git checkout master~2
would give you the commit hash333
.
Upvotes: 1
Reputation: 9933
If you want to go with any certain commit or want to code of any certain commit then you can use below command:
git checkout <BRANCH_NAME>
git reset --hard <commit ID which code you want>
git push --force
Example:
git reset --hard fbee9dd
git push --force
Upvotes: 3
Reputation: 25094
To just download a commit using the 7-digit SHA1 short form do:
Working Example:
https://github.com/python/cpython/archive/31af650.zip
Description:
`https://github.com/username/projectname/archive/commitshakey.zip`
If you have the long hash key
31af650ee25f65794b75d4dfefed6fe4758781c1
, just get the first 7 chars31af650
. It's the default for GitHub.
Upvotes: 17
Reputation: 1152
The easiest way that I found to recover a lost commit (that only exists on github and not locally) is to create a new branch that includes this commit.
git pull
the new branch down to localUpvotes: 11
Reputation: 2289
I don't know if it was there when you had posted this question, but the best and easiest way to download a commit is to click on the commits tab when viewing a repository. Then instead of clicking on the commit name, click on Browse the repository at this point in the history button with <> symbol to the right side of the commit name/message, and finally on the Download ZIP button that comes when you click Clone or Download button.
I hope it helps you guys.
Upvotes: 173
Reputation: 5883
1.Click on commits in github
2.Select Browse code on the right side of each commit
3.Click on download zip , which will download source code at that point of time of commit
Upvotes: 44
Reputation: 467181
First, clone the repository using git, e.g. with:
git clone git://github.com/facebook/facebook-ios-sdk.git
That downloads the complete history of the repository, so you can switch to any version. Next, change into the newly cloned repository:
cd facebook-ios-sdk
... and use git checkout <COMMIT>
to change to the right commit:
git checkout 91f25642453
That will give you a warning, since you're no longer on a branch, and have switched directly to a particular version. (This is known as "detached HEAD" state.) Since it sounds as if you only want to use this SDK, rather than actively develop it, this isn't something you need to worry about, unless you're interested in finding out more about how git works.
Upvotes: 293