简体   繁体   English

git reset分支到master

[英]Git reset branch to master

I have created a branch for example with branch name branch1. 我创建了一个分支,例如分支名称为branch1。 I made some change to files, folders and also I have some untracked files. 我对文件,文件夹做了一些更改,并且还有一些未跟踪的文件。 Only local, no adds or commit. 仅本地,无添加或提交。

Now I want to return to origin/master so I can make the steps again from the beginning( trying to solve a problem in my site). 现在,我想返回到原点/主站点,以便可以从头开始再次执行步骤(尝试解决网站中的问题)。 I am thinking of these: git clean -f to clean all untracked files, git reset -hard to clean the branch, git branch -d branch_name, and in the end switch to master branch and pull files. 我在想这些:git clean -f清理所有未跟踪的文件,git reset -hard清理分支,git branch -d branch_name,最后切换到master分支并提取文件。

My real scenario is: I am having a online site with two servers. 我的真实情况是:我有一个带有两台服务器的在线站点。 One for production and one for development. 一种用于生产,一种用于开发。 They are using my git. 他们正在使用我的git。 I made a new branch as I described. 正如我所描述的,我做了一个新的分支。 Then I run some scripts which were created some new untracked files and modified some other files. 然后,我运行一些脚本,这些脚本创建了一些新的未跟踪文件,并修改了一些其他文件。 This didn't go right but I found the solution. 这样做不正确,但是我找到了解决方案。 So I want to return back to master and make the steps again from scratch. 因此,我想回到主目录,并从头开始再次执行步骤。 As I said all changes made in the development server locally. 正如我所说,所有在本地开发服务器中所做的更改。 No adds or commits are made. 没有添加或提交。

Am I missing something please? 我想念什么吗? I don't want to mess up my git 我不想弄乱我的git

Remove all untracked files with: 使用以下方法删除所有未跟踪的文件:

git clean --force

Removed all unstaged changes with: 使用以下命令删除了所有未分段的更改:

git reset --hard

Go back to master branch with: 返回主分支:

git checkout master

Then make and switch to a new branch with: 然后使用以下命令制作并切换到新分支:

git checkout -b <newBranchName>

'git checkout master' will bring your files back to the state they were in on master. 'git checkout master'会将您的文件恢复到它们在master上的状态。 Since all edits were done on your local machine, there's no need to do a pull. 由于所有编辑都是在本地计算机上完成的,因此无需进行提取。

'git checkout -b ...' makes and switches you to a new branch so any changes you want to make will be on that new branch based on master. 'git checkout -b ...'进行创建并将您切换到新分支,因此您要进行的任何更改都将位于基于master的新分支上。

Try: 尝试:

git reset --hard # get back you the last commit you worked from

git checkout -b new_branch master # create a new branch from master and switch to

then 然后

git clean -fd # remove everything that is not known by git

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

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