1

Basically I accidentally added the 'files' folder to my commits, so I have four old branches of development that have the 'files' folder listed, with all the files. I don't want to make any other changes to these branches, I just want to remove the files folder, and leave everything else exactly as it is. I tried Googling it with no luck? I'm assuming I'm missing something easy, so any help would be much appreciated.

4

1 に答える 1

4

次のコミットから削除したいだけですか、それともプロジェクト履歴から完全に削除したいですか?

git rm BAD_DIRECTORY && git commit -a前者を行います。このリポジトリを公に共有している場合は、この方法を使用する必要があります。履歴を書き換えると、他のリポジトリと自分のリポジトリの同期が解除されるためです。

後者を行うには、 を使用しますgit filter-branch。履歴の各状態 (コミット) で一連のフィルター (コマンド) をプロジェクトに適用することにより、履歴を書き換えます。ユースケースでは、次のようなものを使用できます。

git filter-branch --index-filter "git rm --cached --ignore-unmatch BAD_DIRECTORY"

を使用する--index-filterと、コミットごとにチェックアウトを行う必要がなくなり、時間を節約できます。詳細については、マニュアル ページを参照してください。BAD_DIRECTORY が特定のコミットに存在しない場合に追加すると、失敗しなくなります--ignore-unmatchgit rm

于 2013-05-10T23:10:46.297 に答える