Reputation: 15
i was wondering how to change the order of my commits on git (priority of versions), or to define a commit as "default" for cloning ?
For example, i've three commits for my git project :
-s0441254z5 | "new features in dev" (most recent)
-p44mo47877 | "ENDED project"
-g487er54ee | "First commit" (the oldest)
I would have
-p44mo47877 | "ENDED project"
-s0441254z5 | "new features in dev" (most recent)
-g487er54ee | "First commit" (the oldest)
so when someone do "git clone" on my project, he gets the "ENDED project". I know i could answer this example with another way, using --branches, but it's just an example to illustrate my question. So what do you think about this?
Upvotes: 1
Views: 2121
Reputation: 1964
You should have a branch that stays at the commit you want people who are cloning to be on.
You can do this by, while on the branch with all the commits, say the desired commit is the second to most recent (like in your example).
git checkout -b development # creates a new branch to be cloned
git reset --hard HEAD^ # resets the branch to the commit you want
Then when people clone your project they could clone your project from a specific branch.
git clone --branch development <URL>
You could also, (instead of having devs clone the project with a branch option) change what branch HEAD is pointing to. Here is a descriptive example of how to accomplish this.
I don't see why you would want to reorder the commits when cloning on that specific commit would give you the behavior you're looking for. Although, as mentioned in the comments, you can use rebase to reorder your commits.
Upvotes: 1
Reputation: 9238
so when someone do "git clone" on my project, he gets the "ENDED project".
For this, your current branch (which you have checked-out) on the remote should point on the commit. At github you can change it by choosing another "default" branch.
Upvotes: 0
Reputation: 16527
git rebase -i
(or --interactive
) was written precisely for this (and more...). To change the order of the last 3 commits, run
git rebase -i HEAD~3
An editor will pop-up with instructions, reorder the lines, quit your editor, and let git do the rest.
Upvotes: 1