Suggestions for rebasing a branch, skipping a commit in the middle which deleted files #22984
-
Hi, I’d like to hear out some suggestions about a Git problem I faced some days ago, how you would have handled it, and why that would’ve been better. I was in a situation where a commit deleted some files in a remote repo, and other people worked on it and committed after.
The red commit deleted a lot files that needed to be restored, lots of them, spreaded all around the repository, so, I wanted to restore all the deleted files while mantaining the successive commits’ changes. A _ rebase --onto before-purge 755bca9 _ from master was what immediately came to mind, but that broke the repo’s history, so I had to do a reset --soft origin/master , an _ add -A _, and finally a commit. So I basically used Git’s tools but at the end I had to “cheat” to be able to push something correctly, and I spent almost an hour trying different things to achieve what I wanted to do but I ended up having to resort on reset. What could have been a better way to handle the issue? I tried searching the internet but I wasn’t able to find similar situations. Let me know! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
In my opinion, the best way to handle that would have been to use the
This would have created a commit that specifically undid the changes in that commit and only that commit. That would have the benefit of not breaking the repository’s history and it would allow you to specify why you were undeleting those files (rather than using a “Thanos snap” of making the commit disappear). Let us know if you have more questions. |
Beta Was this translation helpful? Give feedback.
-
That looks exactly like what I was looking for. Very useful, thank you! |
Beta Was this translation helpful? Give feedback.
In my opinion, the best way to handle that would have been to use the
git revert
command. In other words, in your specific situation:This would have created a commit that specifically undid the changes in that commit and only that commit. That would have the benefit of not breaking the repository’s history and it would allow you to specify why you were undeleting those files (rather than using a “Thanos snap” of making the commit disappear).
Let us know if you have more questions.