Nice programing

git은 삭제 후 커밋되지 않은 삭제 된 파일을 복구합니다.

nicepro 2020. 9. 29. 18:44
반응형

git은 삭제 후 커밋되지 않은 삭제 된 파일을 복구합니다.


일부 파일을 삭제했습니다.

나는 아직 커밋하지 않았습니다.

파일을 복구하기 위해 작업 공간을 재설정하고 싶습니다.

나는 git checkout ..

그러나 삭제 된 파일은 여전히 ​​없습니다.

그리고 git status보여줍니다 :

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    cc.properties
#   deleted:    store/README
#   deleted:    store/cc.properties
#

git checkout .작업 공간을로 재설정 하지 않는 이유는 무엇 HEAD입니까?


출력은 수행해야 할 작업을 알려줍니다. git reset HEAD cc.properties기타

그러면 rm 작업이 해제됩니다. 그 후에 a를 git status다시 실행 git checkout -- cc.properties하면 파일을 다시 가져 오려면 a 수행해야한다는 메시지가 표시됩니다 .

업데이트 : 내 구성 파일에 있습니다.

$ git config alias.unstage
reset HEAD

보통 언 스테이지에 사용합니다.


삭제를 준비 했으므로 다음을 수행해야합니다.

git checkout HEAD cc.properties store/README store/cc.properties

git checkout . 삭제가 이미 준비된 인덱스에서만 체크 아웃합니다.


그냥 해 git checkout path/to/file-I-want-to-bring-back.txt


모든 복구하려면 unstaged 각각의 단일 경로를 지정하지 않고, 자동으로 한 번에 삭제를 :

git ls-files -d | sed -e "s/\(.*\)/'\1'/" | xargs git checkout --

각 단일 경로를 지정하지 않고 모든 단계적 삭제를 한 번에 자동으로 복구하려면 다음을 수행하십시오.

git status | grep 'deleted:' | awk '{print $2}' | xargs git checkout --

을 수행하고 있으므로 git checkout .분기를 마지막 커밋 상태로 복원하려는 것 같습니다.

당신은 git reset HEAD --hard

경고

이렇게하면 모든 최신 수정 사항이 제거되고 수정 사항이 해제 될 수 있습니다. 예를 들어 작업이 손실 될 수 있습니다. 그것은 수 있습니다 당신이 원하는 것을 할 수 있지만, 체크 아웃 워드 프로세서를 확인합니다.


당신이 사용한 경우

git rm filename

파일을 삭제하려면

git checkout path/to/filename

작동하지 않으므로이 경우

git checkout HEAD^ path/to/filename

작동해야


내 Mac에서 나를 도왔던 명령이 있습니다. 몇 가지 다른 솔루션을 시도했지만 저에게 효과가 없었습니다.

OSX Mavericks의 Git 버전

mac-pro:main chris$ git version
git version 1.8.5.2 (Apple Git-48)

Command

git checkout HEAD -- path/to/file/file.cc

git checkout HEAD -- client/src/pp_web/index.cljs

Use git ls-files to checkout deleted(-d) or modified(-m) files.

git checkout $(git ls-files -d)

see How can I restore only the modified files on a git checkout?


If you want to restore all of the files at once

Remember to use the period because it tells git to grab all of the files.

This command will reset the head and unstage all of the changes:

$ git reset HEAD . 

Then run this to restore all of the files:

$ git checkout .

Then doing a git status, you'll get:

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

Do you can want see this

that goes for cases where you used

git checkout -- .

before you commit something.

You may also want to get rid of created files that have not yet been created. And you do not want them. With :

git reset -- .

Found this post while looking for answers on how to un-delete a file that was deleted in my working directory after a merge from another's branch. No commit was yet made after the merge. Since it was a merge in progress, i could not just add it back using:

$ git reset <commitid#-where-file.cpp-existed> file.cpp

I had to do another step in addition to the reset to bring the file back:

$ git checkout -- file.cpp

If you have not committed any changes all you have to do is stash those changes and you will be back to the last working commit.

git stash
git stash clear
git clean 

if you are looking for a deleted directory.

 git checkout ./pathToDir/*

For me what worked was git checkout {SHA1 of commit with version to restore} "{path to file to restore}"

For example git checkout 5a6b3179e58edff9c90326b9a04284b02fd67bd0 "src-ui/views/includes/radar.pug"

(executed in the branch that we want the file to go into)

After that command executes, the restored file will exist in the original location (which will need to be comited)


If you have installed ToroiseGIT then just select "Revert..." menu item for parent folder popup-menu.


CAUTION: commit any work you wish to retain first.

You may reset your workspace (and recover the deleted files)

git checkout ./*

I had the same problem however none of the above solutions worked for me. What I ended up doing was:
- create an empty file with the same name
- compare this file with its local history
- copy history across to empty file.


1.Find that particular commit to which you want to revert using:

   git log
This command will give you a list of commits done by you .

2.Revert to that commit using :

    git revert <commit id> 

Now you local branch would have all files in particular

참고URL : https://stackoverflow.com/questions/11956710/git-recover-deleted-file-where-no-commit-was-made-after-the-delete

반응형