Ben*_*ari 163 git version-control github git-checkout gitlab
git checkout 'another_branch'
Run Code Online (Sandbox Code Playgroud)
要么
git checkout origin 'another_branch'
Run Code Online (Sandbox Code Playgroud)
要么
git checkout origin/'another_branch'
Run Code Online (Sandbox Code Playgroud)
Elp*_*Kay 163
如果another_branch已在本地存在且您不在此分支上,则git checkout another_branch切换到分支.
如果another_branch不存在但origin/another_branch确实存在,则git checkout another_branch相当于git checkout -b another_branch origin/another_branch; git branch -u origin/another_branch.这是创建another_branch从origin/another_branch,并设置origin/another_branch为上游another_branch.
如果两者都不存在则git checkout another_branch返回错误.
git checkout origin another_branch在大多数情况下返回错误.如果origin是修订版并且another_branch是文件,那么它会检出该修订版的文件,但很可能不是您所期望的.origin主要用于在git fetch,git pull和git push作为远程链接到远程存储库的一个别名.
git checkout origin/another_branch如果origin/another_branch存在则成功.它导致处于分离的HEAD状态,而不是任何分支.如果进行新提交,则无法从任何现有分支访问新提交,并且不会更新任何分支.
dan*_*ter 55
切换到git中的另一个分支.直截了当的回答,
git-checkout - 切换分支或恢复工作树文件
git fetch origin <----this will fetch the branch
git checkout branch_name <--- Switching the branch
Run Code Online (Sandbox Code Playgroud)
在切换分支之前,请确保您没有任何已修改的文件,在这种情况下,您可以提交更改,也可以将其存储.
pol*_*ola 20
日常生活中有用的命令:
git checkout -b "branchname" -> creates new branch
git branch -> lists all branches
git checkout "branchname" -> switches to your branch
git push origin "branchname" -> Pushes to your branch
git add */filename -> Stages *(All files) or by given file name
git commit -m "commit message" -> Commits staged files
git push -> Pushes to your current branch
Run Code Online (Sandbox Code Playgroud)
如果你想从功能分支合并到开发,首先使用命令“ git branch dev/develop ”检查开发分支,然后输入合并命令“ git merge featurebranchname ”
小智 13
[ git checkout "branch_name"]
是另一种说法:
[ git checkout -b branch_name origin/branch_name]
如果"branch_name" 只是远程存在.
git checkout -b branch_name origin/branch_name如果您有多个遥控器,[ ]非常有用.
关于[ git checkout origin 'another_branch']我不确定这是可能的,AFAK你可以使用"fetch"命令 - [ git fetch origin 'another_branch'] 来做到这一点
对我有用的是以下内容:
切换到需要的分支:
git checkout -b BranchName
Run Code Online (Sandbox Code Playgroud)
然后我通过以下方式拉了“主人”:
git pull origin master
Run Code Online (Sandbox Code Playgroud)
小智 6
查看:git branch -a
如果您只有一个分支,请执行以下步骤。
git config --listgit config --unset remote.origin.fetchgit config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*要切换到包含更改的分支,您应该首先执行提取。这是为了保存更改,例如您的package.json或.env文件。
所以:
git fetch
进而:
git checkout <new branch>
这个答案是为那些像我一样被困了一段时间的人准备的。
| 归档时间: |
|
| 查看次数: |
257761 次 |
| 最近记录: |