ruby-on-rails - 将 master 重置为空状态
问题描述
我创建了一个新的 Rails 应用程序并将代码直接从 master 推送到 Github(第一次提交到存储库中)。但是我犯了一个错误,我不想直接从 master 提交这个新的 Rails 应用程序,而是从 master 创建一个新分支并从这个新分支推送新的 Rails 应用程序。
因此,我想:
- 在 Github(remote) 中从 master 中删除提交,所以 master 是 EMPTY
- 从 master 创建一个新分支,并将 master 中的先前提交添加到这个新分支中。
- 推送到 Github。
解决方案
从 Github(remote) 中的 master 删除提交,所以 master 是 EMPTY
您可以创建一个孤立分支 - 孤立分支是没有任何历史记录的分支
# Create "clean" branch
git checkout --orphan <name>
# remove all existing content if you wish
git clean -Xdf && git clean -xdf
从 master 创建一个新分支,并将 master 中的先前提交添加到这个新分支中。
几个选项:
# Option 1 - Start your branch from the last desired commit
git checkout -b <name> <SHA-1>
# Option 2 - Set your branch to the desired commit
git reset <SHA-1> --hard
# Add the required commit on top of your branch
git cherry-pick <SHA-1>
推送到 Github。
# force the update of the new branch
git push <origin> master -f
推荐阅读
- ruby-on-rails - 无法访问 datagrid rails 上的 current_user
- nim-lang - 如何忽略 nim 中的“断管”异常
- android - 谷歌日历事件链接未打开谷歌日历应用事件创建详细信息
- python - python 不支持 RSA 密钥格式
- java - 带有动态参数的 JDBC Select Query
- reactjs - 对孩子的反应行动导致重新渲染父母
- vue.js - VueRouter 在导航后保持组件处于活动状态
- android - Flutter,如何在键盘打开时无缝滚动视图
- powerbi - 将单个表从 DirectQuery 更改为 Import
- python - 在 SQL 中将 Python 列表作为输入传递给 Redshift