GitHub - 如何将项目推到最新阶段,忽略所有旧提交?
GitHub - How to push a project on its latest stage, ignoring all old commits?
我有一个项目想推送到 github,但我想在没有任何旧提交的情况下将其推送到实际阶段。我该怎么做?
编辑。我已经为它创建了一个单独的分支,所以我想在没有其他分支的任何其他提交的情况下推送这个分支。我这样做是因为我添加了一个迟到的 gitignore 并且现在 git ignore 中的所有文件都被版本化并且这个 branch/repository 的目的是审查实际代码几个文件夹。
找出分支的基础:
git merge-base {baseBranch} HEAD
使用命令将分支软重置回第一次提交之前:
git reset --soft {hashOfCommitForYourBase}
git add .; git commit -m "my new message"
再推力:
git push --force
经过一些研究,我发现了这个 answer,作者建议使用命令 git checkout --orphan
,而这正是我要找的,使用这个命令我可以创建一个新分支,没有其他分支的历史痕迹,这样我就可以只用我需要显示的文件推送到存储库。
我刚刚执行了以下步骤:
// Created a new orphan branch
git commit --orphan <branchname>
// at this point I have edited all my files, and set the .gitignore
// cleared cached files, so I have no issues with .gitignore files
git rm --cached -r -f .
// added all files
git add .
// commited the changes
git commit -m 'new orphan branch'
// pushed to the repository
git push <repositoryname> <localbranchname>
我有一个项目想推送到 github,但我想在没有任何旧提交的情况下将其推送到实际阶段。我该怎么做?
编辑。我已经为它创建了一个单独的分支,所以我想在没有其他分支的任何其他提交的情况下推送这个分支。我这样做是因为我添加了一个迟到的 gitignore 并且现在 git ignore 中的所有文件都被版本化并且这个 branch/repository 的目的是审查实际代码几个文件夹。
找出分支的基础:
git merge-base {baseBranch} HEAD
使用命令将分支软重置回第一次提交之前:
git reset --soft {hashOfCommitForYourBase}
git add .; git commit -m "my new message"
再推力:
git push --force
经过一些研究,我发现了这个 answer,作者建议使用命令 git checkout --orphan
,而这正是我要找的,使用这个命令我可以创建一个新分支,没有其他分支的历史痕迹,这样我就可以只用我需要显示的文件推送到存储库。
我刚刚执行了以下步骤:
// Created a new orphan branch
git commit --orphan <branchname>
// at this point I have edited all my files, and set the .gitignore
// cleared cached files, so I have no issues with .gitignore files
git rm --cached -r -f .
// added all files
git add .
// commited the changes
git commit -m 'new orphan branch'
// pushed to the repository
git push <repositoryname> <localbranchname>