如何使用 git 切换回“master”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7417166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:50:21  来源:igfitidea点击:

How to switch back to 'master' with git?

git

提问by Disco

I have made my first commit; then created a branch (let's say branch1).

我已经做出了我的第一次承诺;然后创建了一个分支(假设分支 1)。

In this branch I've created a directory 'example' and commited. In GitHub I see my new branch and the new directory 'example' that I have added.

在这个分支中,我创建了一个目录“example”并提交。在 GitHub 中,我看到了我的新分支和我添加的新目录“example”。

Now I wonder how can I 'sync' back to master; and so have the 'example' folder deleted (as it doesn't exist on master).

现在我想知道如何“同步”回主人;因此删除了“示例”文件夹(因为它在主服务器上不存在)。

EDIT : find . -type d -empty -exec touch {}/.gitignore \;did the job.

编辑:find . -type d -empty -exec touch {}/.gitignore \;完成了工作。

回答by Matthew Farwell

You need to checkout the branch:

您需要结帐分支:

git checkout master

See the Git cheat sheetsfor more information.

有关更多信息,请参阅Git 备忘单

Edit: Please note that git does not manage empty directories, so you'll have to manage them yourself. If your directory is empty, just remove it directly.

编辑:请注意,git 不管理空目录,因此您必须自己管理它们。如果你的目录是空的,直接删除即可。

回答by blacksta500

According to the Git Cheatsheetyou have to create the branch first

根据Git Cheatsheet,您必须先创建分支

git branch [branchName]

and then

进而

git checkout [branchName]

回答by Sachin Sridhar

For deleting the branch you have to stash the changes made on the branch or you need to commit the changes you made on the branch. Follow the below steps if you made any changes in the current branch.

要删除分支,您必须存储在分支上所做的更改,或者您需要提交在分支上所做的更改。如果您在当前分支中进行了任何更改,请按照以下步骤操作。

  1. git stashor git commit -m "XXX"
  2. git checkout master
  3. git branch -D merchantApi
  1. git stash或者 git commit -m "XXX"
  2. git checkout master
  3. git branch -D merchantApi

Note: Above steps will delete the branch locally.

注意:以上步骤会在本地删除该分支。

回答by Dan Ray

I'm trying to sort of get my head around what's going on over there. Is there anything IN your "example" folder? Git doesn't track empty folders.

我试图弄清楚那边发生了什么。您的“示例”文件夹中是否有任何内容?Git 不跟踪空文件夹。

If you branched and switched to your new branch then made a new folder and left it empty, and then did "git commit -a", you wouldn't get that new folder in the commit.

如果您分支并切换到新分支,然后创建一个新文件夹并将其留空,然后执行“git commit -a”,则不会在提交中获得该新文件夹。

Which means it's untracked, which means checking out a different branch wouldn't remove it.

这意味着它未被跟踪,这意味着检查不同的分支不会删除它。

回答by Dapo Momodu

Will take you to the master branch.

将带您到 master 分支。

git checkout master

git checkout master

To switch to other branches do (ignore the square brackets, it's just for emphasis purposes)

切换到其他分支做(忽略方括号,只是为了强调目的)

git checkout [the name of the branch you want to switch to]

git checkout [the name of the branch you want to switch to]

To create a new branch use the -blike this (ignore the square brackets, it's just for emphasis purposes)

要创建一个新分支,请使用-b像这样(忽略方括号,只是为了强调目的)

git checkout -b [the name of the branch you want to create]

git checkout -b [the name of the branch you want to create]