Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从现有项目创建git分支_Git_Merge_Branch - Fatal编程技术网

如何从现有项目创建git分支

如何从现有项目创建git分支,git,merge,branch,Git,Merge,Branch,我有一个项目不是git的,我想将它与git下的另一个项目合并。 有哪些步骤可以做到这一点 git init git remote add origin git@bitbucket.org:projectname/reponame.git git pull origin master 然后git希望我提交任何东西来创建本地主分支 git add something git commit -m 'Initial' 但是我想像做一个新的分支一样做这个,好的,做一个新的分支 git branch n

我有一个项目不是git的,我想将它与git下的另一个项目合并。 有哪些步骤可以做到这一点

git init
git remote add origin git@bitbucket.org:projectname/reponame.git
git pull origin master
然后git希望我提交任何东西来创建本地主分支

git add something
git commit -m 'Initial'
但是我想像做一个新的分支一样做这个,好的,做一个新的分支

git branch newbranch
git checkout newbranch
那么接下来呢?我想留下我的主人,把它并入纽伯兰。 当我再次尝试拉动时,我发现:

git pull origin master
From bitbucket.org:projectname/reponame
 * branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
        .gitignore
        .htaccess
        ...
Please move or remove them before you can merge.
Aborting
如何告诉git-好的,去做吧!
最后,我希望有两个分支:master(就像在origin一样)和merged newbranch(我的现有代码+origin/master)

首先,您必须提交所有代码

提交代码后,签出要保留其内容的分支。执行
git merge
,您在签出需要保留的文件时会遇到任何冲突

例如:

# Checkout the required branch (local or remote)
git checkout master

# merge the branches
git pull origin master

# in case you have conflicts:
# If you want to keep the version of your master use the --ours flag
git checkout --ours <file>

# second option if to merge use the merge strategy 
git merge -s recursive -X ours <branch>
#签出所需的分支(本地或远程)
切换到主分支
#合并分支
git拉源主机
#如果您有冲突:
#如果您想保留master的版本,请使用--ours标志
git结帐——我们的
#如果要合并,请使用合并策略
git merge-s recursive-X ours

据我所知,您正在尝试将新分支与主分支合并。在这种情况下,您需要先签出主分支,而不是先将其拉入

git checkout master
git pull origin master
git merge <your new branch name>
git push origin master
git签出主机
git拉源主机
git合并
git推送源主机
另外,可以做的是,可以使用git-rebase选项将分支上的最新更改与master合并

git checkout <branch name>
git rebase master
git签出
git重基主控器
它将要做的是,将应用最近在master顶部所做的更改。 在此之后,您可以签出主分支并进行快速合并

git checkout master
git merge <branch name>
git签出主机
git合并