简体   繁体   English

git:如何用'dev'分支中的文件更新'master'分支?

[英]git: How to update 'master' branch with a file from the 'dev' branch?

I am quite new to 'git', although I have a moderate amount of experience with 'svn' already, but I have never had the need to make use of branches with either system until now. 我对'git'还是很陌生,尽管我已经对'svn'有一定的经验,但是到目前为止,我从来不需要在任何一个系统中使用分支。

I am working on my first (small) collaborative project, and so have made a dev branch and have been working on my dev/test changes on the dev branch (and have uploaded them to the dev branch in the repo). 我的工作我的第一个(小)合作项目等方面都取得了dev分支,一直在我的开发/测试的变化dev分支(并将它们上传到dev中回购分支)。 My current version of the code is now ready to become the new master version (before then working on the next dev revision). 现在,我当前的代码版本已准备就绪,可以成为新的master版本(在进行下一个dev修订之前)。

I see that another collaborator has since added a new file (which does not affect the file that I am working on) to the master branch (which I was not previously aware of, as I am in the dev branch locally). 我看到另一个协作者此后向master分支(我以前不知道,就像我在本地的dev分支一样)中添加了一个新文件(这不会影响我正在处理的文件)。

I now need to update the version of " myfile " in the master branch with the version of " myfile " from the dev branch, while not affecting the " theirfile " that the other developer added (and, I suppose, also ideally downloading " theirfile " to my local copy of the master branch as well). 现在,我需要使用dev分支中的“ myfile ”版本来更新master分支中的“ myfile ”版本,同时又不影响其他开发人员添加的“ thefilefile ”(而且,我认为最好也下载“ theyfile”以及我在master分支的本地副本)。

I knew that I would need to deal with this issue in due course, but the presence of this additional file in the master branch on the repo perhaps makes things a little more complicated. 我知道我将在适当时候处理此问题,但是该附加文件在回购协议的master分支中可能会使事情变得更加复杂。

As I am still not too familiar with 'git', and, especially, as I don't want to inadvertently mess up our code repo, could someone please advise what I need to do to update the repo accordingly? 由于我仍然不太熟悉'git',尤其是因为我不想无意间弄乱我们的代码存储库,所以有人可以建议我需要做些什么来相应地更新存储库吗?

You want to be merging into your master branch with that file. 您想将该文件合并到您的master分支中。 Depending on the git client that you are using you might want to submit a merge request so that the rest of your team can verify this change. 根据您使用的git客户端,您可能希望提交合并请求,以便团队的其他成员可以验证此更改。

If this is the only file that you have edited, or you are confident that all files in your 'dev' branch are the same as - or updated - versions of their corresponding files in master then use the following command. 如果这是您唯一编辑过的文件,或者您确信'dev'分支中的所有文件都与master中其相应文件的版本相同(或已更新),请使用以下命令。

git checkout master
git merge dev
git add '{your updated files}'
git commit
git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM