如何将单个文件合并回原始文件并将其推送到git中的远程文件?
答案 0 :(得分:1)
听起来你想要这样做:
# add the file you care about to the index
# if other stuff is already there, use git reset HEAD to wipe it out first
git add <important-file>
# stash away all other modifications, but keep the index
git stash --keep-index
# stash the single file from the index
git stash
# check out the master branch
git checkout master
# apply the change to the single file (your second stash)
git stash pop
# commit
git commit
# return to the other branch
git checkout <other-branch>
# restore the first stash (all other work)
git stash pop
如果你想把它记录为合并,而不是直接提交给master,你可以创建一个新的分支来检出,提交它,检查master,然后合并它(而不是检查master和commit,就像我上面做的那样。)
答案 1 :(得分:1)
您需要做的就是:
git checkout master
git checkout other_branch -- path/your_file
git add . -A
git commit -m "your message"
git push origin master
这假设“起源”是您的遥控器。
答案 2 :(得分:0)
抱歉,我不确定您的问题是什么意思,是否要将对单个文件所做的所有更改保存到存储库,在这种情况下您将使用git commit -a
,或者您是否希望merge
您所在的分支,其中包含一个新文件,返回原始分支,在这种情况下,您将使用git checkout master
,然后git merge name_of_branch_to_merge
。要获取用于协作或在远程计算机上工作的存储库版本,我认为您接下来要问的是,您可以使用git clone /path/to/original/repository name_of_new_repository
,然后使用新创建的name_of_new_repository
目录将包含您可以单独处理原始分支的原始分支的文件和历史记录。