Reputation: 754
I am a newbie to 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:
I ran git merge --no-commit --no-ff <myBranchName>
. After I ran this, it showed me some conflicts. Then I did git status and result was:
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
. 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:
# 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. 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).
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!
Upvotes: 1
Views: 1323
Reputation: 61437
git doesn't know about files not in the index. To remove files unrelated to the current branch, including non-tracked ones, run
git clean -fd .
Upvotes: 1