开发者

placing a file from a branch back into master

开发者 https://www.devze.com 2023-01-24 05:23 出处:网络
how can I merge a single file back to the original and push it to the re开发者_运维问答mote in git?It sounds like you want to do this:

how can I merge a single file back to the original and push it to the re开发者_运维问答mote in git?


It sounds like you want to do this:

# 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

If you want to record this as a merge, instead of committing directly to master, you could create a new branch to check out, commit to it, check out master, and merge it (instead of checking out master and committing, like I did above).


all you need to do is:

git checkout master
git checkout other_branch -- path/your_file
git add . -A
git commit -m "your message"
git push origin master

This assumes "origin" is your remote.


Sorry, I'm not sure what you mean by the question, do you want to save all changes done to a single file to the repository, in which case you would use git commit -a, or do you want to merge the branch you're on, that contains a new file, back to the original branch, in which case you'd use git checkout master and then git merge name_of_branch_to_merge. For getting a version of the repository to use for collaborative or for work on a remote machine, which is what I think you're asking next, you can use git clone /path/to/original/repository name_of_new_repository, and then the newly created name_of_new_repository directory will contain the files and history of the original branch that you can work on separately to the original.

0

精彩评论

暂无评论...
验证码 换一张
取 消