问题描述
我在我的项目中做了一个很大的重构:我重命名了文件,删除了,添加...另外,我在.gitignore中添加了一些文件夹。但是,我已经在重构之前对远程存储库进行了提交。
有没有必要让git重新启动我的存储库?如果没有,我该怎么办?
更新:
我已删除文件夹.git,现在我有一个错误:
我不想将本地更改与远程回购合并,我只是想推到那里,意思是完全替换远程本地存储库。
更新
如果您删除了 .git
文件夹(不是一个好主意),您可以创建一个新的回购克隆并将其移动到该目录,并继续那里。就像这样
cd ..
git clone< remote-repo-url> new-repo
rm -rf new-repo / * //这不会删除new-repo / .git
cp -f< original-local-repo>新回购
cd新回购
然后继续如下。
请注意,如果您可以恢复 .git
文件夹,则效果会更好。创建一个新的回购将松散您在原始本地回购中的所有本地回购信息,例如从未推入的本地分支。
$ b
END UPDATE
你可以
git reset --soft HEAD ^
git add -A。
git commit -m重写历史记录
git push --force原始大师
这将备份到先前的提交(同时保留工作树和索引),提交您的更改,然后强制将重写的历史推送到远程。
push --force
是危险的东西。它会打扰已经拉过的人,并且被认为是非常粗鲁的,但是如果没有其他人开始工作,那不是问题。
这就是正在发生:
--- A - B主人
^
| b
$ b git reset HEAD ^
git commit -amrewriting
--- A - B来源/主人
\
\
B'主人
git push --force
--- A - B
\
\
B'master,origin / master
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
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.
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
这篇关于“重新启动”知识库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!