defensive-git
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese変更の破棄禁止ルール
Rule Prohibiting the Discarding of Changes
既存の作業ツリーやインデックスにある未コミットの変更は、ユーザーの貴重な作業内容です。作業が終わるまで変更を消したり捨てたりすることは、厳しく禁止します。
Uncommitted changes in the existing working tree or index are valuable user work. Until the task is complete, deleting or discarding these changes is strictly prohibited.
1. 禁止コマンド一覧
1. List of Prohibited Commands
同等の働きをするフラグやオプションも含めて、次のコマンドの実行を禁止します。
- 作業ツリー・インデックスの変更破棄
- /
git reset --hard/git reset --merge(変更やインデックスを強制リセットして消去する)git reset --keep - /
git checkout .(作業ツリー上の編集内容を取り消す)git checkout -- <file> - /
git checkout -f(未コミット変更を無視・上書きしてブランチを切り替える)git switch -f - /
git restore .(作業ツリーやステージ上の変更を破棄して元に戻す)git restore <file> - (追跡されていない新規ファイルや無視ファイルを物理削除する)
git clean
- ファイル・退避データ(Stash)の消去
- (退避失敗や誤操作によるデータ紛失のリスクがある)
git stash - (追跡ファイルを作業ツリーごと物理削除する)
git rm -f - (未コミット変更が残る作業領域を丸ごと削除する)
git worktree remove --force
- コンフリクト(競合)調整中の破棄
- /
git checkout --ours(競合時に片方の変更を完全に上書きして捨てる)git checkout --theirs - /
git merge --abort(マージ・リベース作業を中断し調整中の内容を破棄する)git rebase --abort - (適用中の変更内容をスキップして捨てる)
git rebase --skip
- ブランチ・リモート履歴の強制削除
- (未マージの作業中・退避用ブランチを強制削除する)
git branch -D - /
git push --force(リモートの履歴を強制書き換えして作業ログを消去する)git push -f
Running the following commands, including equivalent flags or options, is prohibited.
- Discarding changes in the working tree or index
- /
git reset --hard/git reset --merge(forcibly resets and erases changes or the index)git reset --keep - /
git checkout .(cancels edits in the working tree)git checkout -- <file> - /
git checkout -f(ignores or overwrites uncommitted changes when switching branches)git switch -f - /
git restore .(discards and restores changes in the working tree or staging area)git restore <file> - (physically deletes new untracked files and ignored files)
git clean
- Deleting files or stashed data (Stash)
- (risks data loss due to failed stashing or incorrect usage)
git stash - (physically deletes tracked files from the working tree)
git rm -f - (removes an entire working area that may contain uncommitted changes)
git worktree remove --force
- Discarding changes while resolving conflicts
- /
git checkout --ours(completely overwrites and discards one side of the changes during a conflict)git checkout --theirs - /
git merge --abort(aborts merge or rebase work and discards the changes being resolved)git rebase --abort - (skips and discards the changes being applied)
git rebase --skip
- Force-deleting branches or remote history
- (force-deletes an unmerged work-in-progress or stash branch)
git branch -D - /
git push --force(force-overwrites remote history and erases the work log)git push -f
2. 破壊的変更の検出と回避
2. Detecting and Avoiding Destructive Changes
コマンドやスクリプトを実行する前に、現在の作業ツリーの状態を確認してください。
- 状態確認: タスクを始める前に必ず を実行し、未コミットの変更(Modified / Untracked)がないか確認してください。
git status - 競合のチェック: 変更予定のファイルがすでに編集されている場合は、既存のコードを消さずに変更箇所を統合するか、ユーザーに編集してよいか確認してください。
- 新規ファイルの扱い: 未追跡ファイル(Untracked files)がある場合でも、削除やクリーンアップは行わないでください。
Before running commands or scripts, check the current state of the working tree.
- Status check: Before starting a task, always run and verify whether there are any uncommitted changes (Modified / Untracked).
git status - Conflict check: If a file to be changed has already been edited, integrate the new changes without deleting the existing code, or ask the user whether it is acceptable to edit the file.
- Handling new files: Even if untracked files (Untracked files) exist, do not delete or clean them up.
3. 安全な代替手順
3. Safe Alternative Procedures
変更を保持したまま作業を安全に進めるために、状況に応じて以下の手順を選択してください。
- 作業途中の変更を一時的に確定したい場合:
一時的なコミットを作成して退避します。
bash
git add . git commit -m "wip: save uncommitted changes before task" - 新規ブランチで作業したい場合:
既存の変更を保持したまま新しいブランチへ切り替えます。
bash
git checkout -b feature/your-task-name
To proceed safely while preserving changes, choose the appropriate procedure below based on the situation.
- If you want to temporarily save changes while working:
Create a temporary commit to preserve them.
bash
git add . git commit -m "wip: save uncommitted changes before task" - If you want to work on a new branch:
Switch to a new branch while preserving the existing changes.
bash
git checkout -b feature/your-task-name