記事ディレクトリ
特定の変更が比較的大きい場合、より多くのファイルが関係します。ただし、あるファイルは元々は問題なかったのですが、余分であることが判明し、問題が発生しました。このとき、バージョンを直接ロールバックすると、すべてのコードがロールバックされてしまい、ローソクの価値がない可能性があります。このとき、単一のファイルを変更前のバージョンにロールバックするように指定する必要があります。
- まず、ロールバックする必要があるファイル パスを取得します。より簡単な方法は、無関係なコメントなどの小さな変更をファイルに追加してから、パスを表示することです
git status
。
➜ git:(test) git status
On branch test02
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
# modified:后面的就是文件路径
modified: packages/pages/src/table/index.vue
no changes added to commit (use "git add" and/or "git commit -a")
- パスを取得したら、変更をロールバックします。
git checkout -- .
➜ git:(test) ✗ git checkout -- .
➜ git:(test) git status
On branch test02
nothing to commit, working tree clean
- 次に、
commit
バージョン情報を確認します。git log
の後ろの数字は、確認するレコードの数を示します。
➜ git:(test) git log -2
commit 555a38d888d4c3743491ddeb8a4235c4ec3cc49b (HEAD -> test)
Author: 流星
Date: Tue Feb 14 11:20:15 2023 +0800
chore: 登录功能大改
commit 6f53d8d8d4d570082e580554b68d36707f50421b
Author: 流星
Date: Mon Feb 13 16:45:21 2023 +0800
feat: 添加登录功能
(END)
-
ログイン機能の大幅な変更に問題があるため、このファイルをログイン機能が追加された時点までロールバックする必要があります
-
事前にコピーしておくべきものは次の 2 つです。
1. 需要回退的文件路径:packages/pages/src/table/index.vue
2. 需要回退到哪的 commit ID:6f53d8d8d4d570082e580554b68d36707f50421b
- 次に、以下を実行します。
git checkout ID 路径
➜ git:(test) git checkout 6f53d8d8d4d570082e580554b68d36707f50421b packages/pages/src/table/index.vue
Updated 1 path from 1ccf76171
- このとき、ログイン機能の大幅な変更前のコードに戻りますが、変更の必要がなければこの時点で表示されます
commit
。
➜ git:(test) ✗ git status
On branch test02
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: packages/pages/src/table/index.vue
➜ git:(test) ✗ git commit -m 'chore: 还原某某文件'
→ No staged files match any configured task.
✔ Preparing lint-staged...
✔ Running tasks for staged files...
✔ Applying modifications from tasks...
✔ Cleaning up temporary files...
--------------------- git add ------------------
Nothing specified, nothing added.
hint: Maybe you wanted to say 'git add .'?
hint: Turn this message off by running
hint: "git config advice.addEmptyPathspec false"
---------------------- done --------------------
[lstest02 758a23df5] chore: 还原某某文件
1 file changed, 1 insertion(+), 1 deletion(-)