简体   繁体   English

git merge --no-commit --no-ff`后如何`git reset`

[英]How to `git reset` After `git merge --no-commit --no-ff`

I am a newbie to git. 我是git的新手。 I was working on a branch that involved lot of moving around of the code, including deletion of old and addition of new files. 我在一个分支中工作,涉及许多代码的移动,包括删除旧文件和添加新文件。 Therefore I decided to do a dry-run of git merge before actually merging: 因此,我决定在实际合并之前先进行git merge的试运行:

I ran git merge --no-commit --no-ff <myBranchName> . 我跑了git merge --no-commit --no-ff <myBranchName> After I ran this, it showed me some conflicts. 运行此命令后,它显示了一些冲突。 Then I did git status and result was: 然后我做了git status,结果是:

My-Macbook-pro:[master] $ git status
# On branch master
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#
# Changes to be committed:
#   modified:   common/TP.php
#   deleted:    common/model/Job/Request.php
#   new file:   common/DP.php
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   both modified:      .gitignore
#   both added:         build/release/current/production.sql
#   deleted by them:    common/Service/DFPASPAdapter.php
#   both modified:      common/Ze.php
#   deleted by them:    common/model/provider/DFPASP.php

Then to undo git add (which happened because of the git merge dry run), I ran git reset HEAD . 然后要撤消git add (由于git merge dry run而发生),我运行了git reset HEAD But later on I realized/learnt that in order to get back to the stage the master branch was in before merge(ie exactly same as what is committed to master), I will need to run git reset --hard HEAD After I ran the hard reset, git status shows the following: 但是后来我意识到/了解到为了回到合并之前master分支所在的阶段(即与提交给master的对象完全相同),我将需要运行git reset --hard HEAD硬重置, git status显示以下内容:

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   build/release/current/upgrade.php
#   common/F1.php
#   common/F2.php
#   common/F3.php
nothing added to commit but untracked files present (use "git add" to track)

The above files F1, F2, F3 and upgrade.php were added in the branch that I was working on. 上面的文件F1,F2,F3和upgrade.php已添加到我正在处理的分支中。 I was hoping that git reset --hard HEAD will make the master branch forget about anything related to the branch I was trying to merge (dry run). 我希望git reset --hard HEAD将使master分支忘记与我尝试合并(空运行)的分支有关的任何内容。

Is this something that is possible? 这有可能吗? Is there something I am missing in the concept? 我在概念中缺少什么吗? And am I left with the only option of removing the files manually? 我是否只有手动删除文件的选项? Any help in making me understand more will be great! 使我了解更多的任何帮助都将非常有用! Thanks! 谢谢!

git doesn't know about files not in the index. git不知道不在索引中的文件。 To remove files unrelated to the current branch, including non-tracked ones, run 要删除与当前分支无关的文件,包括非跟踪文件,请运行

git clean -fd .

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

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