Answer the question
In order to leave comments, you need to log in
How to remove/commit only the required commit?
After a long time, I made another commit in the repo, and found that 20 other useless commits sailed with it (did samples), which are not needed at all in the remote repository (and in the local one too). Now it is not clear how to remove them from there.
I tried different ways, such as git revert, git reset --hard changed places, but something doesn’t work out.
Ideally, I want to commit only the last commit, and remove intermediate ones or ignore them when git pushing to Bitbucket.
Answer the question
In order to leave comments, you need to log in
git rebase -i HEAD~N
- where N is the number of garbage commits. You will need to squash. To do this, write p (pick up) on the first line, and s (squash) on the rest.
After fixing the situation in the local repository, force push:git push -f
In general, it’s better to do tests in a separate branch - this way there are much fewer headaches ...
If you still want to save the tests (at least temporarily), then you can do this:
So you have aaaaaa commit (the last one you write about) and there is commit sssss. Trial commits are somewhere between aaaaaa and sssss. The master branch, according to your description, is at the very top, i.e. on aaaaa.
1. Create a test branch: git branch Tests (now there are two branches on aaaaaa)
2. Move master to the last useful commit: git reset --hard cccccc
3. Copy the desired commit: git cherry-pick aaaaaa
4. Push master: git push - f
You can visualize the situation like this: git log --oneline --decorate --all --graph
All. Trial commits remained in a separate branch. It can be removed. And if they are still needed and it is supposed to continue working there, then you need to do a rebase:
5. git checkout Tests
6. git rebase
master it's already downstairs.
PS: In order not to write a long git log (this is a very common command), I advise you to make alias.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question