[英]how tell 'git' to 'forget' ALL prior commits?
我需要根據我的另一個項目的一小部分開始一個新項目,我的回購是在github。
我在一個新的項目文件夾中做了一個git clone ...很好。
我刪除了我不需要的一切,擺脫了舊的遷移等......好吧。
現在它在本地運行正常,但'git log'顯示所有舊提交。
我想告訴git“忘記所有先前的提交,這是一個新項目,所以在此之前忘記一切,從現在開始作為第一次提交”
我讀到了關於git rebase但是不清楚這是否是正確的命令,如果是這樣,如何將它用於這個非常簡單的目的。
刪除.git
文件夾,運行git init
和git add
這里接受的答案真的讓我感到害怕 - 刪除你的.git
目錄是一件非常艱巨的事情,而且這里沒有必要。
這個腳本使用更安全的方法 - 它創建一個名為old-master
的分支來記錄你開始git reset --soft $ROOT_COMMIT
提交之前的位置,然后使用git reset --soft $ROOT_COMMIT
和git commit --amend
將整個分支git commit --amend
到一個承諾。 您也可以從這個GitHub要點下載腳本。
#!/bin/bash
# A script that squashes your entire current branch down to a single commit,
# if this repository has a single root commit. This will change the object
# name of the root commit.
if [ -n "$(git status --porcelain)" ]
then
echo "git status wasn't clean - refusing to run..."
exit 1
fi
# From: http://stackoverflow.com/questions/1006775/
root_commits () {
git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$"
}
NUMBER_OF_ROOT_COMMITS=$(root_commits|wc -l)
if (( "$NUMBER_OF_ROOT_COMMITS" > 1 ))
then
echo "This script won't work when you have multiple root commits"
exit 1
fi
ROOT_COMMIT=$(root_commits)
if [ -z "$ROOT_COMMIT" ]
then
echo "No root commit was found!"
exit 1
fi
set -e
set -x
# Create a branch based on the current HEAD for safety:
git branch old-master
# Reset the branch to the root commit, leaving the previous
# state of the tree staged:
git reset --soft $ROOT_COMMIT
# Now amend the root commit with the state of the index:
git commit --amend -m "The branch restarted"
為什么不將該目錄復制到一個全新的git存儲庫並將其提交到那里?
你試過reposurgeon
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.