将文件提交到另一个没有签出的分支 [英] Commit a file to a Different Branch Without Checkout
问题描述
是否有可能在git分支中提交文件而不检出该分支?如果是这样怎么做?
基本上我希望能够在我的github页面分支中保存一个文件,而不必一直切换分支。任何想法?
更新:不能做我想做的事情(请参阅下面的用例评论)。我最终做的是以编程方式将当前目录克隆到tmp目录,然后在tmp目录中检出我的分支(不影响我的工作目录)并将我的文件提交到tmp目录clone。完成后,我会推回到我的工作目录并删除tmp目录。吮吸,但它是将文件提交到另一个分支而不更改工作目录的当前工作分支的唯一方法。如果有人有更好的解决方案,请随时在下面添加它。如果它比'不能做'好,我会接受你的。 这是不可能的。
您提交的更改与当前的工作副本有关。如果你想提交到另一个分支,这意味着你可以从你的工作副本提交更改,但是将它们从另一个副本状态作为基础。
这不是您工作版本化的自然方式,这就是为什么您需要进行不同的步骤(存储更改,检出分支,弹出存储和提交)到完成它。
至于你的具体用例,一个简单的方法是保留你的工作的两个副本,一个签出在 在 Is it possible to commit a file in a git branch with out checking out that branch? If so how? Essentially I want to be able to save a file in my github pages branch without switching branches all the time. Any thoughts? Update: It's not possible to do what I want (see comments below for use case). What I ended up doing is programmatically cloning my current directory to a tmp directory, then checking out my branch in that tmp directory (doesn't affect my working directory) and committing my files to the tmp directory clone. When I'm done, I push back to my working directory and delete the tmp directory. Sucks, but it's the only way to commit files to another branch without changing the current working branch of the working directory. If anyone has a better solution, please feel free to add it below. If it's better than 'it cannot be done', I'll accept yours. It's not possible. The changes you commit are related to the current working copy. If you want to commit to another branch it means that you could commit changes from your working copy, but base them from another copy state. This is not a natural way of versioning your work, and this is why you need to make different steps (stash changes, checkout the branch, pop stash and commit) to accomplish it. As for your specific use case, a simple way is to keep two copies of your work, one checked out at In the 这篇关于将文件提交到另一个没有签出的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! master code>分支,另一个在
页面
分支。
$ b $ 页面
工作副本中,添加 master
复制为远程回购。
master
master
在页面
复制
master
branch, and the other at pages
branch. pages
working copy, add the master
copy as a remote repo.
master
master
on the pages
copy