简体   繁体   中英

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.

I have a master branch. 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). I did quite some work on this local copy and I also updated the master branch to resolve some bugs and pushed the changes.

Now I want to create a new branch new_version for this new branch on which I worked locally. Then I want to merge the modifications from master into 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.

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 . Then, take your local copy and copy it over the original directory (making sure, again, that there is no .git directory in your copy). Then, simply commit your changes with git add . and 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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