0

I have pushed a folder with high number of files to git remote repository. Now how to remove that folder from the commit and push the changes again to the remote repository?

Akash Khandelwal
  • 346
  • 1
  • 4
  • 10
  • delete the folder---->git commit --> git push – Parth Ghiya May 18 '17 at 11:08
  • If you only want to remove them, them remove them, commit that, and push. If you want to also remove them from the history you will have to look into history rewriting. Either [rebase](http://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git), or stage an old commit, branch, and remove the old branch, or look into the [git-rewrite-history](http://stackoverflow.com/questions/tagged/git-rewrite-history) tag for something that fits your needs. – Theraot May 18 '17 at 11:17

1 Answers1

0

First, remove the commit on your local repository. You can do this using git rebase -i. For example, if it's your last commit, you can do git rebase -i HEAD~2 and delete the second line within the editor window that pops up.

Then, force push to GitHub by using git push origin +branchName

See Git Magic Chapter 5: Lessons of History - And Then Some for more information (i.e. if you want to remove older commits).

Oh, and if your working tree is dirty, you have to do a git stash first, and then a git stash apply after.


OR you can use :

git reset --hard HEAD~1
LuFFy
  • 8,799
  • 10
  • 41
  • 59
  • On removing the commit from my local repository, my changes might be gone. If so, how do I get the changes of that commit back? – Akash Khandelwal May 18 '17 at 15:56
  • if you use `git reset --hard HEAD~1` Your last commit will be converted to `modified` files which will have your code inside it, try it in a sample project. – LuFFy May 18 '17 at 20:48