订购 git 次提交

Ordering git commits

我想知道如何更改 git 上的提交顺序(版本优先级),或者将提交定义为 "default" 以进行克隆?

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)

我会

-p44mo47877 | "ENDED project"
-s0441254z5 | "new features in dev" (most recent)
-g487er54ee | "First commit" (the oldest)

所以当有人在我的项目上做 "git clone" 时,他会得到 "ENDED project"。 我知道我可以用另一种方式回答这个例子,使用--branches,但这只是一个例子来说明我的问题。 所以,对于这个你有什么想法?

您应该有一个分支保留在您希望克隆人所在的提交处。

你可以这样做,在所有提交的分支上,说所需的提交是倒数第二个提交(就像你的例子一样)。

git checkout -b development # creates a new branch to be cloned
git reset --hard HEAD^  # resets the branch to the commit you want

然后当人们克隆你的项目时他们可以clone your project from a specific branch

git clone --branch development <URL>

您也可以(而不是让开发人员使用分支选项克隆项目)更改 HEAD 指向的分支。 Here 是如何完成此操作的描述性示例。

我不明白你为什么要在克隆特定提交时重新排序提交会给你正在寻找的行为。尽管如评论中所述,您可以使用 rebase to reorder your commits.

git rebase -i(或--interactive)正是为此(以及更多...)编写的。要更改最后 3 次提交的顺序,运行

git rebase -i HEAD~3

编辑器将弹出一个带有说明的窗口,重新排列行,退出编辑器,让 git 完成剩下的工作。

so when someone do "git clone" on my project, he gets the "ENDED project".

为此,远程上的当前分支(您已检出)应指向提交。在 github 您可以通过选择另一个 "default" 分支来更改它。