-1

So I have a git stash master branch(?) and I CD'd into the wrong folder and pushed all the contents to the master.

How do I get rid of everything and start again, and push the correct folder contents?

git init
Initialized empty Git repository in D:/apps/myapp_old/.git/
git add --all
git commit -m "Initial commit"
git remote add origin https://url/my_app.
git push -u origin master

I tried this:

$ git rm -r *
fatal: pathspec 'tmp' did not match any files
user3437721
  • 2,227
  • 4
  • 31
  • 61

2 Answers2

2

How do I get rid of everything and start again, and push the correct folder contents?

If you just want to remove the current content of the repository and start all over again:

Simply delete the .git folder and add any content you want

  rm -rf .git 
  git init 
  git add .
  git commit -m "message"

How to remove content already in the remote repo?

# remove any content from the repo
git rm --cached <any files you want to remove"

# update the removed files
git add . -A 

# commit the file you have deleted
git commit -m "..."

# push changes
git push origin <branch>

NOTE: The content will be in the repository and in the next commits it will be removed



How to remove content from the repository and all its history

You can user interactive rebase of git filter-branch

In order to edit and change the history (rebase) follow those steps:

// X is the number of commits you wish to squash
git rebase -i HEAD~X

Once you squash your commits - choose the e for edit, when the process stops remove the desired file and then continue and commit your changes.

enter image description here

Once you have completed the rebase push the changes with git push -f

NOTE: Rebase is a destructive and should only be done on branches which no one else has checkout or their work will be lost.


More Options:

How to change the content of the repo - reverting or undoing

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
1

You're going to have to remove all of the source files that you accidentally added in your local branch, recommit, and re-push to the remote.

TriskalJM
  • 2,393
  • 1
  • 19
  • 20