Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone git repository with specific revision/changeset?

How can I clone git repository with specific revision, something like I usually do in Mercurial:

hg clone -r 3 /path/to/repository 
like image 586
John Avatar asked Aug 15 '10 20:08

John


People also ask

How do I clone a specific version of a git repository?

git clone <repository> . Alternatively, you can perform git-clone and then check out a specific revision with git-checkout. git clone <repository> . That's all about cloning a Git repository with a specific revision.

How do I clone a specific tag?

git clone If you only need the specific tag, you can pass the --single-branch flag, which prevents fetching all the branches in the cloned repository. With the --single-branch flag, only the branch/tag specified by the --branch option is cloned. $ git clone -b <tagname> –single-branch <repository> .

Can I clone a specific branch?

There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.

How do you git pull a specific commit?

How do I pull a specific commit? The short answer is: you cannot pull a specific commit from a remote. However, you may fetch new data from the remote and then use git-checkout COMMIT_ID to view the code at the COMMIT_ID .


1 Answers

$ git clone $URL $ cd $PROJECT_NAME $ git reset --hard $SHA1 

To again go back to the most recent commit

$ git pull 

To save online (remote) the reverted commit, you must to push enforcing origin:

git push origin -f 
like image 80
Vaibhav Bajpai Avatar answered Oct 02 '22 21:10

Vaibhav Bajpai