I searched this but unable to find my answer. And I just want to know the non command line way to do this.... Or is there any other way to achieve this same ?
1 Answers
You can delete files (from a repo you own, like a fork)
But you cannot directly from the web interface delete commits.
For that you would need to clone, do an interactive rebase (dropping the commits you don't want) and git push --force
.
Even a revert does not seem possible.
The OP adds:
Actually I have 3 branches one is
master
and rest two arepatch-1
andpatch-2
and I messed up withmaster
branch before creatingpatch-1
andpatch-2
branches so some useless commits are also cloned frommaster
topatch-1
andpatch-2
branch so please can you help me to delete those commits which are cloned frommaster
?
No without cloning the repo though:
git clone /url/of/your/fork
cd yourfork
git remote add upstream /url/original/repo
git fetch upstream
git checkout -b patch-1 origin/patch-1
git checkout -b patch-2 origin/patch-2
Then replay your patches on top of upstream master
:
git rebase --onto upstream/master master patch-1
git rebase --onto upstream/master master patch-2
Finally reset master
to the upstream master
branch:
git checkout master
git reset --hard upstream/master
And then push everything back to your fork:
git push --force --mirror

- 1,262,500
- 529
- 4,410
- 5,250
-
Actually I have 3 branches one is master and rest two are patch-1 and patch-2 and I messed up with master branch before creating patch-1 and patch-2 branches so some useless commits are also cloned from master to patch-1 and patch-2 branch so please can you help me to delete those commits which are cloned from master – Golu Mar 14 '18 at 07:26
-
Actually I m new to github and I cloned repo as you suggested but now I m confused how to delete commits ... You have any reference link for my situation or you can guide me ? – Golu Mar 14 '18 at 07:33
-
-
Thank you very much for your help But I have one doubt and I want to clear by doubt before implementing your steps .I gave a pull request from patch-1 branch to original repo/master or project so, my doubt = is your steps will affect my PR (PR is still not merged) – Golu Mar 14 '18 at 08:22
-
@Golu The final push --force will override the remote patch-x branch, and will automatically update your PR. Except that updated existing PR won't have the extra commits from your old master, that you don't want. – VonC Mar 14 '18 at 08:23
-
Thnx but I am stuck at your 5th command which is for rebase error is fatal: no such branch/commit 'patch-2' – Golu Mar 14 '18 at 10:48
-
-
I mean, obviously replace those names with the accueil name of your patch branches – VonC Mar 14 '18 at 10:51
-
-
Yes I am trying with my original branch names which is Hax4us-patch-1 and Hax4us-patch-2 ..... But not working same error of no such branch – Golu Mar 14 '18 at 10:53
-
Can you please add this additional command in your answer in appropriate location – Golu Mar 14 '18 at 10:54
-
-
-
@Golu Great. I have edited the answer to add the missing command: that might be helpful to others as well. – VonC Mar 14 '18 at 12:24