I've made kind of a big refactoring in my project: I renamed files, removed, added... Besides, I added some folders in .gitignore. However, I've already made a commit to a remote repository before refactoring.
Is there any to make git "reinit" for my repository? If there is not, what should I do?
Update:
I have deleted the folder .git and now I have an error of
hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I don't want to merge the local changes with the remote repo, I just want to push there, meaning completely replace the remote repository with the local one.
Adding a remote repository To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: A remote name, for example, origin.
UPDATE
If you have deleted the .git
folder (not a great idea), you can create a new clone of the repo and move your stuff to that, and continue there. Something like this
cd .. git clone <remote-repo-url> new-repo rm -rf new-repo/* // this will not remove new-repo/.git cp -f <original-local-repo> new-repo cd new-repo
Then continue as below.
Note that it is better if you can restore the .git
folder. Creating a new repo will loose all local repo information you had in the original local repo, like local branches that were never pushed.
END UPDATE
You could
git reset --soft HEAD^ git add -A . git commit -m "rewriting history" git push --force origin master
This will back up to the previous commit (while preserving the working tree and index), commit your changes, and then force push that rewritten history to the remote.
push --force
is dangerous stuff. It will disturb others who have already pulled, and is considered very rude, but if no one else have started work on it, that is not a problem.
This is what is happening:
--- A -- B master ^ | origin/master git push --- A -- B master, origin/master git reset HEAD^ git commit -am "rewriting" --- A -- B origin/master \ \ B' master git push --force --- A -- B \ \ B' master, origin/master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With