当使用git时,你如何将精确的工作目录推送到远程? [英] When using git, how do you push the exact working directory to a remote?

查看:115
本文介绍了当使用git时,你如何将精确的工作目录推送到远程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程git仓库和一个本地克隆。假设我失去了本地的.git目录,然后向本地工作目录中添加和删除了一些文件。



在某些时候,我想重新初始化本地回购,将它连接到远程,并最终将本地工作目录推送到远程(就是说,我希望所有添加/删除的文件在远程中都是相同的)。



我会如何完成这项工作?



这是我目前的解决方案,我不喜欢(也可能不适用于所有情况)。



git init

git remote add origin [some_url]



git add。 #添加工作目录中的所有文件
$ b $ git commit -m添加文件

点,我目前的想法是:


  • 创建分支,


  • <
  • 'git diff master branch> my_patch'


  • li>

    将该补丁应用到分支,

  • 从分支推送到远程,



  • 并杀死分支。


>

显然,我的想法相当复杂和难看。任何想法?

解决方案

像这样的东西(假设你是从丢失的.git时刻开始的)?
$ b

 #将当前目录设置为git存储库。 
#这让你在没有提交的主分支上。
git init

#添加对远程存储库的引用。
git remote add origin urlurlurl

#获取远程文件。
git fetch

#在不触摸工作树的情况下,将master分支
#从远处移动到远程主设备上。
git reset origin / master

#分配新索引和当前树之间的所有更改。
git add -A

#提交这些更改。
git commit -m新的工作树作为远程主服务器上的补丁


I have a a remote git repo and a local clone. Let's say I lose my local .git directory and subsequently add and remove some files to the local working directory.

At some point, I want to re-init the local repo, connect it to the remote, and ultimately push my local working dir to the remote exactly as it is (which is to say, I want to have all the added/deleted files be the same in the remote)

How would I accomplish this?

Here is my current solution, which I don't like (and may not work in all cases).

git init

git remote add origin [some_url]

git add . # adds all the files in the working dir

git commit -m "adding files"

(At this point, my current idea is to:

  • make a branch,

  • fetch the remote into it,

  • 'git diff master branch > my_patch'

  • apply that patch to the branch,

  • push from the branch to the remote,

  • pull into the master,

  • and kill the branch.)

Clearly my idea is quite complex and ugly. Any ideas?

解决方案

Something like this (assuming you are starting from the lost .git moment)?

# 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时,你如何将精确的工作目录推送到远程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆