简体   繁体   English

git-从本地副本创建一个新分支,然后将其与现有分支合并

[英]git - create a new branch from local copy and then merge it with existing branch

Being a git newbie, I have messed up a little bit in the way I handled a new development and I do not succeed in resolving this properly. 作为git新手,我在处理新开发的过程中有些混乱,但未能成功解决此问题。

I have a master branch. 我有一个master分支。 I made a local copy of this master branch on my desktop computer and then I removed the hidden .git folder (don't ask me why). 我在台式计算机上制作了该master分支的本地副本,然后删除了隐藏的.git文件夹(不要问我为什么)。 I did quite some work on this local copy and I also updated the master branch to resolve some bugs and pushed the changes. 我在此本地副本上做了很多工作,还更新了master分支以解决一些错误并推送了更改。

Now I want to create a new branch new_version for this new branch on which I worked locally. 现在,我想为此我在本地工作的新分支创建一个新分支new_version Then I want to merge the modifications from master into new_version . 然后,我想将master的修改合并到new_version

How can I do that ? 我怎样才能做到这一点 ?

In my local branch I tried the following which ended up in a total mess: 在我的本地分支机构中,我尝试了以下操作,但最终却一团糟:

git init
git pull my_repo master

So I reverted to the initital state where this local new branch was not even a git repository. 因此,我恢复到初始状态,在该状态下,该本地新分支甚至都不是git存储库。

Assuming you mean that you made a local copy of the root folder and worked on it (without the .git directory), simply go back to the original directory and make sure you are up to date with git pull . 假设您的意思是制作了根文件夹的本地副本并对其进行了处理(没有.git目录),只需返回原始目录并确保您使用git pull是最新的。 Then, take your local copy and copy it over the original directory (making sure, again, that there is no .git directory in your copy). 然后,获取本地副本并将其复制到原始目录中(再次确保副本中没有.git目录)。 Then, simply commit your changes with git add . 然后,只需使用git add .提交更改即可git add . and git commit . git commit

First create a branch from the point where you made a copy of your master branch 首先从复制主分支的位置创建一个分支

git branch <branch name> <sha1>

Then copy all of your files from your copy into the working copy, all your changes should now show as diffs. 然后将所有文件从副本复制到工作副本,所有更改现在都应显示为差异。

git commit -am'new stuff made'

Commit your changes and then rebase from master to have all recent changes applied 提交您的更改,然后从主服务器更改基准以应用所有最近的更改

git rebase master

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

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