我有一个远程 git 仓库和一个本地克隆。假设我丢失了本地 .git 目录,随后在本地工作目录中添加和删除了一些文件。
在某些时候,我想重新初始化本地存储库,将它连接到远程,并最终将我的本地工作目录完全原封不动地推送到远程(也就是说,我想要添加的所有内容/删除的文件在远程是一样的)
我将如何完成这个?
这是我目前的解决方案,我不喜欢它(并且可能并非在所有情况下都有效)。
初始化
git remote add origin [some_url]
git 添加。 # 添加工作目录中的所有文件
git commit -m "添加文件"
(此时,我目前的想法是:
创建一个分支,
将 Remote 放入其中,
'git diff master branch > my_patch'
将该补丁应用到分支,
从分支推送到远程,
pull 进高手,
并杀死分支。)
显然,我的想法非常复杂和丑陋。有什么想法吗?
最佳答案
像这样的事情(假设你是从丢失的 .git 时刻开始的)?
# Make the current directory a git repository.
# This puts you on a master branch with no commits.
git init
# Add a reference to the remote repository.
git remote add origin urlurlurl
# Fetch the remote refs.
git fetch
# Without touching the working tree, move master branch
# from nowhere onto the remote master.
git reset origin/master
# Stage all changes between the new index and the current tree.
git add -A
# Make a commit of these changes.
git commit -m "New working tree as a patch on remote master"
关于git - 使用 git 时,如何将确切的工作目录推送到远程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/471896/