1

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 ?

Golu
  • 350
  • 2
  • 14
  • Using a desktop tool doesn't always mean command line. You can use SourceTree, TortoiseGit, etc. – Cœur Mar 14 '18 at 05:46

1 Answers1

1

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 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?

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
VonC
  • 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
  • @Golu I have updated the answer to include the precise steps. – VonC Mar 14 '18 at 07:34
  • 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
  • Do you have a patch-2 branch? – VonC Mar 14 '18 at 10:50
  • I mean, obviously replace those names with the accueil name of your patch branches – VonC Mar 14 '18 at 10:51
  • Or checkout them first: Git checkout -b patch-2 origin/patch-2 – VonC Mar 14 '18 at 10:52
  • 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
  • I have in my previous comment – VonC Mar 14 '18 at 10:55
  • git checkout -b my branch_name origin/mybranch_name r8 ? – Golu Mar 14 '18 at 11:00
  • @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