我正在寻找一种方法将master上的所有提交合并到一个提交中,并最终重写一个新提交以从一个新的开始开始。
答案 0 :(得分:1)
如果要保留现有的存储库配置,可以执行以下操作:
git checkout master
git branch backup
:可选择创建备用分支,以防您保留历史记录。git reset --soft $SHA_OF_INIT_COMMIT
:这将更新HEAD
指向的内容,但保留索引和工作目录的当前状态。git commit --amend
:将您的初始提交更改为指向您的回购的当前状态。git push --force
:强制推送到origin/master
以更新远程存储库(如果有的话)。我刚试过这个,它就像一个魅力。这归功于Kevin M Granger。在此之后,您可能还希望在本地和远程存储库上运行git gc
(如果有的话)。 git gc
在当前存储库中运行许多内务处理任务,例如压缩文件修订(以减少磁盘空间和提高性能)以及删除无法访问的对象。
答案 1 :(得分:0)
您可以删除.git文件夹,只需将当前源用作新Git仓库中的“初始提交”。
答案 2 :(得分:0)
Use following Commands and Steps:
1) git rebase -i HEAD~2 origin/master #2 is no of commits you want to fix
Following window will open up
pick 03d633e refactor
pick d51b770 Updating Username comment
# Rebase 2868146..d51b770 onto 2868146 (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
"~/WebstormProjects/Working/.git/rebase-merge/git-rebase-todo" 21L, 700C
2) To fixup : change pick to "fixup" or "f" and Save file .
pick 03d633e refactor
fixup d51b770 Updating Username comment
3) Verify same using command:
git log --oneline
4)force push changes :(Be Careful)
git push origin HEAD:master --force