简体   繁体   中英

how to bring back a file that is deleted and committed but still present in the branch on git hub

I have 7 files on my git hub branch. i deleted 4 of them and made commit, but did not push. Now, I want those 4 deleted files back. other branch have same data and i tried merging, it says ' branch is updated ' but wont show those 4 files. I tried pull, and there is no help.

git checkout origin/my-branch-name -- ./path/to/deleted/file

You could find the commit when the file was deleted (it will log all deleted files and commits):

git log --diff-filter=D --summary

And then checkout the file:

git checkout <commit>~1 <filename>

There are two ways to get back those files:

1) if it's your recent commit then you simply reset its to get back your files. git reset HEAD~1

2) if its older commit then you can revert it by

git revert your_deleted_branch_commit_hash

Let me know if it resolved the issue

Thanks!

Use following commands if you have not pushed yet.

If you want your changes in staging area (ready to commit) use

git reset --soft HEAD^

This will remove your commit which is not pushed and put the changes in staging. if your remove the changes with commit use hard as an option

git reset --hard HEAD^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM