Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

git commit - Git revert removing files that shouldn't be removed

I have three commits and I tried reverting back to the first commit. In doing that, Git removed two files and I don't know why as they were in the first commit I tried reverting to. If the two files Git removed were in the original commit, why did it remove them?

This is the code I used:

git revert <commit id>

and this is the error message:

    Removing style.css
CONFLICT (modify/delete): pages/services.html deleted in (empty tree) and modified in HEAD. Version HEAD of pages/services.html left in tree.
Removing index.html
error: could not revert 9b23173... inital commit
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If what you want to take back the content of the project to a certain revision while keeping the later history, it can be done like this:

git checkout the-revision-id
git reset --soft the-branch-I-want-to-take-back
# at this point, all changes from the branch you want to take back and the revision you want to go to are in index, ready to be committed
git commit -m "taking everything back in time"
# if you like the result, move the pointer of the branch
git branch -f the-branch-I-want-to-take-back
git checkout the-branch-I-want-to-take-back

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...