0

I have a project with a lot of commits and I would like to create a new branch called old that ends with a commit 707f3c4, which is in the past. How would I do that?

d33tah
  • 10,999
  • 13
  • 68
  • 158
  • 1
    What does "ends with a commit" mean? Do you want to create a branch based on this commit? – nwinkler Mar 04 '15 at 12:13
  • I'd like the branch to stop with a given commit, as opposed to the "master" branch where there are commits after this one. – d33tah Mar 04 '15 at 12:14
  • 1
    @d33tah Branches don't really ‘stop’ anywhere. What are you trying to achieve? Couldn't you use tags instead? – Biffen Mar 04 '15 at 12:15
  • possible duplicate of [Tag older commit in Git](http://stackoverflow.com/questions/4404172/tag-older-commit-in-git) – nwinkler Mar 04 '15 at 12:16
  • Do you mean creating a tag? If so, please refer to the linked question. – nwinkler Mar 04 '15 at 12:16

3 Answers3

1

This command should do the trick:

git checkout -b old 707f3c4
davidriod
  • 937
  • 5
  • 14
  • This also has the side-effect of checking out the new `old` branch, meaning you'll have to `git checkout master` to get back to where you were. The `git branch` command will create a branch without affecting your working directory – Gareth Mar 04 '15 at 13:39
1

Just this:

git branch old 707f3c4

Note that a branch is only a moveable alias for a commit, it doesn't "start" or "end" anywhere or even have any history.

Gareth
  • 133,157
  • 36
  • 148
  • 157
0

If you want to create a tag on a certain commit, you can use

git tag -a old 707f3c4 -m "Create old tag"

Then push the tag using

git push --tags
nwinkler
  • 52,665
  • 21
  • 154
  • 168