While working on a a feature-specific branch (from the 'development' branch), I took the wrong approach (a few times :/) and essentially want to delete all my commits on this branch before my current commit.
What I've done before in this type of situation is to do a git rebase -i development
and delete all commits before the one I want to keep (the most current) and then do a git push --force to update the remote repo to contain only my most recent golden commit.
After doing this, when its time for me to commit the changes for this rebase commit, it looks like git is responding a bit strangely to my request. There are a few files that it says
both modified: app/helpers/statistics_helper.rb
deleted by us: app/models/referrals/chart.rb
deleted by us: app/views/statistics/_referrals.html.haml
deleted by us: app/views/statistics/_referrals2.html.haml
deleted by us: app/views/statistics/_referrals3.html.haml
I dont know how to respond to this. if I git add
the files that are preceded by "deleted by us", will it delete these files?
By removing the the commits it is as if they never happened. So if you added any files in the previous commits that were just removed those files will be removed, too. That is probably while you are seeing that message. This will probably remove changes to preexisting files that you wanted as part of your end result as well. I think you're using rebase incorrectly.
If at the end of your last commit everything is in the state you want it to be you should simply squash your last commits instead. You can do this a couple ways. Using rebase -i
as you did and specifying s
or squash
instead of edit
for all commit lines except the first will do that.
The other way to do it would be:
git reset --soft HEAD~<N>
git commit
Where <N>
is the number of commits back you need to squash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With