1

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?

ford prefect
7,41611 gold badges60 silver badges86 bronze badges
asked Aug 23, 2017 at 13:37
3
  • 4
    git rebase -i is your friend. Commented Aug 23, 2017 at 13:42
  • 1
    To elaborate on git rebase -i, the pick lines can be reordered to your ultimate desire. Commented Aug 23, 2017 at 20:20
  • your way of presenting the history is not clear. Is it list of branches or list of commits? You could use commands git branch -v or git log --oneline --decorate to show them. It would be understood better. Commented Aug 24, 2017 at 3:44

3 Answers 3

1

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.

answered Aug 23, 2017 at 14:11
Sign up to request clarification or add additional context in comments.

Comments

1

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.

answered Aug 23, 2017 at 13:50

2 Comments

the reset HEAD~1 and checkout . can be replaced by reset --hard HEAD^ :-)
@petrpulc Thank you.
0

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.

answered Aug 24, 2017 at 3:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.