TortoiseHg - How to remove files from a branch after pushing to remote repository

280 views Asked by At

I have modified, committed and pushed: fileA, fileB, and fileC. I should only have pushed "fileA" and "fileB", and my pull request has been declined due to this unwanted fileC.

Baring in mind that I have pushed these changes to the remote repository, is there a way for me to fix this locally so my pull request will not include fileC any more?

2

There are 2 answers

0
planetmaker On

Simply create a new head with all necessary commits, starting to branch-off at the same parent where your 'wrong' changeset is based on. Then create a new pull-request for that new head you thus created.

Afterwards, you can opt to remove the unwanted head with the changeset(s) which include the unwanted fileC, however that should not be necessary. The strip command will come in handy for that (it's an extension and needs activation in your mercurial config file)

0
Desphilboy On

There are 2 ways doing that: 1- Fixing the repository and correcting the history so your incorrect commit is also cleaned from the history:

a- do a git log:

Desphilboy@computer:~/workspace/project(master)$ git log
commit dee4f318231b07ca3dbf213579dbfdeb89f72591
Author: Desphilboy<[email protected]>
Date:   Wed Jul 13 11:04:43 2016 +1000

    feat(project): this is a wrong commit pushing FileC

commit e9772baa0abefc3423db2e6b518c71bade74abd9
Author: Somebody else<[email protected]>
Date:   Tue Jul 12 12:05:18 2016 +1000

    feat(project): added new API endpoint 
....    

b- do a reset --soft to the hash code before that wrong commit:

Desphilboy@computer:~/workspace/project(master)$ git reset --soft e9772baa0abefc3423db2e6b518c71bade74abd9

this will revert your commit while keeping all your changes. if you do a git status now you will see all your changes after that commit

c- delete FileC and do another commit and push it again using -f switch

Desphilboy@computer:~/workspace/project(master)$ rm FileC 
Desphilboy@computer:~/workspace/project(master)$ git rm FileC
Desphilboy@computer:~/workspace/project(master)$ git add .
Desphilboy@computer:~/workspace/project(master)$ git commit -m "some commit message"
Desphilboy@computer:~/workspace/project(master)$ git push -f

2- Keeping history: you can simply delete the fileC, remove it from repo, commit and push your local to the master again. this will correct your problem but there will be an additional commit to the master and it will be shown in the history.