Восстановить отсутствующий файл после `read-tree --empty` и` reset --hard` - PullRequest
0 голосов
/ 09 апреля 2020

ОС: Ubuntu 19.10
git: 2.20.1

Я просто трачу много времени на написание документации. Я сохранил файл уценки в папке проекта моего сайта документации как: content/topics/workflow/docker/git-workflow.md

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore
        modified:   .prettierignore
        ...
        modified:   src/templates/topic/pages.html

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        content/topics/workflow/docker/git-workflow.md

no changes added to commit (use "git add" and/or "git commit -a")

Как вы можете видеть, новый документ не отслежен, но есть также множество измененных файлов. Это произошло из-за проблемы с окончаниями строк в папке (^M):

$ git diff
diff --git a/.gitignore b/.gitignore
index dcf9f37..f1a3279 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
-.env
-dist
-tmp
-node_modules
-.vscode
+.env^M
+dist^M
+tmp^M
+node_modules^M
+.vscode^M
diff --git a/.prettierignore b/.prettierignore
index d282fbc..81f839a 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -1,4 +1,4 @@
-src/templates/**/header.html
-src/templates/**/footer.html
-nav.html
+src/templates/**/header.html^M
+src/templates/**/footer.html^M
+nav.html^M
 pages.html
\ No newline at end of file
diff --git a/content/topics/aws/dbaccess/authorize-ip-in-aws.md b/content/topics/aws/dbaccess/authorize-ip-in-aws.md
index a37f9ee..7ffb9dc 100644
--- a/content/topics/aws/dbaccess/authorize-ip-in-aws.md
+++ b/content/topics/aws/dbaccess/authorize-ip-in-aws.md
@@ -1,50 +1,50 @@
-## Step 1
-

Немного оглянувшись, я наткнулся на этот ответ о переполнении стека на вопрос это было похоже на то, что у меня было в то время.

$ git add --renormalize .

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   .gitignore
        ...
        modified:   src/templates/topic/pages.html

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        content/topics/workflow/docker/git-workflow.md

Принятый ответ не сработал, поэтому я попытался выполнить мягкий сброс:

$ git reset HEAD -- .
Unstaged changes after reset:
M       .gitignore
...
M       content/topics/workflow/1overview/starting-with-a-fresh-repo.md
M       content/topics/workflow/docker/setup.md
M       content/topics/workflow/merging/meta.json
...
M       src/templates/topic/pages.html

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore
        ...
        modified:   src/templates/topic/pages.html

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        content/topics/workflow/docker/git-workflow.md

no changes added to commit (use "git add" and/or "git commit -a")

Как видите, это тоже не сработало. Я решил попробовать предложения во втором ответе:

$ git help read-tree

$ git read-tree -n --empty

Поскольку после запуска dry выходных данных не было, я решил, что можно продолжить:

$ git read-tree --empty

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    .gitignore
        ...
        deleted:    content/topics/workflow/1overview/what-next.md
        deleted:    content/topics/workflow/docker/installation.md
        deleted:    content/topics/workflow/docker/meta.json
        deleted:    content/topics/workflow/docker/setup-docker-on-windows-home.md
        deleted:    content/topics/workflow/docker/setup.md
        deleted:    content/topics/workflow/docker/usage.md
        deleted:    content/topics/workflow/merging/meta.json
        ...
        deleted:    src/templates/topic/pages.html

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        .netlify/
        .prettierignore
        README.md
        content/
        gulpfile.js
        index.js
        netlify.toml
        package-lock.json
        package.json
        src/


$ git commit -m 'fix line endings?'
[master f65c8e2] fix line endings?
 111 files changed, 8013 deletions(-)
 delete mode 100644 .gitignore
 ...
 delete mode 100644 content/topics/workflow/1overview/what-next.md
 delete mode 100644 content/topics/workflow/docker/installation.md
 delete mode 100644 content/topics/workflow/docker/meta.json
 delete mode 100644 content/topics/workflow/docker/setup-docker-on-windows-home.md
 delete mode 100644 content/topics/workflow/docker/setup.md
 delete mode 100644 content/topics/workflow/docker/usage.md
 delete mode 100644 content/topics/workflow/merging/meta.json
 ...
 delete mode 100644 src/templates/topic/pages.html

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        .netlify/
        .prettierignore
        README.md
        content/
        gulpfile.js
        index.js
        netlify.toml
        package-lock.json
        package.json
        src/

nothing added to commit but untracked files present (use "git add" to track)

$ git add .

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   .gitignore
        ...
        new file:   content/topics/workflow/docker/git-workflow.md
        ...
        new file:   src/templates/topic/pages.html

Вы Можно видеть, что содержимое / themes / workflow / docker / git -workflow.md было добавлено к вышеописанному этапу. На данный момент, однако, я не хотел, чтобы это массовое удаление и добавление файлов в моей истории git. Итак, я решил (тупо) сделать полный сброс последнего коммита.

$ git reset --hard HEAD^
HEAD is now at a6daf28 add .env.php note

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Я начал пани c. Что случилось с моим новым файлом документации?

$ graph
* a6daf28 (HEAD -> master, origin/master) add .env.php note
* 08845e9 add note about .txt for db_root_password
* c7ba3ab fix typos, add windows 10 home warning
...
* 3d19355 adding production repo setup documentation

Я решил вернуться к состоянию головы перед полным сбросом:

$ git reflog
a6daf28 (HEAD -> master, origin/master) HEAD@{0}: reset: moving to HEAD^
f65c8e2 HEAD@{1}: commit: fix line endings?
a6daf28 (HEAD -> master, origin/master) HEAD@{2}: commit: add .env.php note
08845e9 HEAD@{3}: commit: add note about .txt for db_root_password
c7ba3ab HEAD@{4}: commit: fix typos, add windows 10 home warning
...

$ git reset --hard f65c8e2
HEAD is now at f65c8e2 fix line endings?

Но теперь, каталог content (с мой новый файл) ушел.

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .vscode/
        dist/
        node_modules/

nothing added to commit but untracked files present (use "git add" to track)

Здесь я действительно начал пани c. Я решил (опять же, изумительно) сбросить настройки СНОВА.

$ git reset --hard HEAD^
HEAD is now at a6daf28 add .env.php note

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Я только начал пробовать случайные вещи, которые точно не будут работать:

$ git pull
Warning: Permanently added the RSA host key for IP address 'REDACTED' to the list of known hosts.
Already up to date.

$ git push
Everything up-to-date

$ git reset --hard HEAD^
HEAD is now at 08845e9 add note about .txt for db_root_password
$ git reflog
08845e9 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
a6daf28 (origin/master) HEAD@{1}: reset: moving to HEAD^
f65c8e2 HEAD@{2}: reset: moving to f65c8e2
a6daf28 (origin/master) HEAD@{3}: reset: moving to HEAD^
f65c8e2 HEAD@{4}: commit: fix line endings?
a6daf28 (origin/master) HEAD@{5}: commit: add .env.php note
08845e9 (HEAD -> master) HEAD@{6}: commit: add note about .txt for db_root_password
c7ba3ab HEAD@{7}: commit: fix typos, add windows 10 home warning
...
$ git reset --hard f65c
HEAD is now at f65c8e2 fix line endings?
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .vscode/
        dist/
        node_modules/

nothing added to commit but untracked files present (use "git add" to track)
$ git ls-files -d | sed -e "s/\(.*\)/'\1'/" | xargs git checkout --
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .vscode/
        dist/
        node_modules/

nothing added to commit but untracked files present (use "git add" to track)
$ graph
* f65c8e2 (HEAD -> master) fix line endings?
* a6daf28 (origin/master) add .env.php note
* 08845e9 add note about .txt for db_root_password
* c7ba3ab fix typos, add windows 10 home warning
...

После всего этого вот последний рефлог:

f65c8e2 (HEAD -> master) HEAD@{0}: reset: moving to f65c
08845e9 HEAD@{1}: reset: moving to HEAD^
a6daf28 (origin/master) HEAD@{2}: reset: moving to HEAD^
f65c8e2 (HEAD -> master) HEAD@{3}: reset: moving to f65c8e2
a6daf28 (origin/master) HEAD@{4}: reset: moving to HEAD^
f65c8e2 (HEAD -> master) HEAD@{5}: commit: fix line endings?
a6daf28 (origin/master) HEAD@{6}: commit: add .env.php note
08845e9 HEAD@{7}: commit: add note about .txt for db_root_password
c7ba3ab HEAD@{8}: commit: fix typos, add windows 10 home warning
8fd9f35 HEAD@{9}: commit: update setup documentation
83ca65d HEAD@{10}: commit: docker setup documentation complete
8305494 HEAD@{11}: commit: not sure where that file came from
6758e4f HEAD@{12}: commit: added docker workflow
18a5ec2 HEAD@{13}: commit: add git gc
2ed635d HEAD@{14}: pull: Fast-forward
7f02337 HEAD@{15}: commit: updated phpmyadmin docs and git docs
3f55c45 HEAD@{16}: commit: updated docs with lastpass data
7c7dfbb HEAD@{17}: commit: updated docs with lastpass data
cee8bc6 HEAD@{18}: commit: fixed typo
10daf0f HEAD@{19}: commit: added db access documentation
c579c0e HEAD@{20}: commit: fixed bulleting
27dc0c0 HEAD@{21}: commit: added security audit process docs
8ed0326 HEAD@{22}: commit: add migration documentation
ae44fb5 HEAD@{23}: pull: Merge made by the 'recursive' strategy.
2b2ec9c HEAD@{24}: commit: not sure

Я не могу понять, как вернуть этот файл. Я даже пытался:

$ sudo find / -name "git-workflow.md"

Но, увы, результатов не было.

Любая помощь в поиске отсутствующего файла будет принята с благодарностью.

1 Ответ

0 голосов
/ 09 апреля 2020

Я смог найти файл благодаря этому ответу и следующим командам:

$ git fsck --cache --no-reflogs --lost-found --dangling HEAD
$ cd .git/lost-found/other
$ cat ./*
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...