0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

フォルダを誤ってGitにコミットした時の削除方法

0
Posted at

1.はじめに

この記事では、誤ってプッシュしてしまったフォルダをGitから削除する手順を、シンプルに解説します。
最近Next.jsの開発を始めたのですが、.nextフォルダをGithubにコミット・プッシュしてしまったのでその時の備忘録としてここにまとめておきます。
皆さんの削除したいフォルダ・ファイルに読み替えて参考にしてください。

2. .gitignore.next/ を追加する

まずは再発防止のために .gitignore に以下を追加します。

.next/

これにより、今後 .next が Git の追跡対象になるのを防げます。

3. Git から .next を削除する手順

すでに Git にプッシュされている .next を削除するには、以下の手順を実行します。

# Git の追跡対象から削除(ローカルのフォルダは残る)
git rm -r --cached .next

# 削除をコミット
git commit -m "Remove .next folder from repository"

# リモートに反映
git push origin main

※ブランチ名が main でない場合は適宜変更してください。

4. まとめ

  • .next は Next.js の自動生成フォルダ → Git で管理不要
  • .gitignore に追加し、誤ってプッシュした場合は git rm -r --cached で削除
  • 基本的に .next は削除しても再生成されるので安心です
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?