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
Here are steps to re-init repository.
Scenario: I have deleted a locally project folder that I have made git init previously. After that, I would like to update to the existing git repository with a new folder of same project. Then I solved it by following procedure.
Procedure
git init
git add --all
git commit -am "re-init"
git remote add origin https://github.com/{yourgit}/{yourproject}.git
git push --force origin master
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
The lazy way is to just add all the new files and changes, and deletions:
git add -A .
So long as you don't have any conflicts, this should merge in fine.