简体   繁体   中英

Git commit confusion between branches and master

I've gotten myself in a bit of a tangle with GitHub (for Mac, though I doubt that's relevant).

I am only a recent convert to Git, so it remains an unknown in many respects, and today was the first time I'd had a reason to have two branches active at the same time.

I'm not sure what happened, but a merge between one of the branches and master didn't go according to plan (somehow, the commit summary got lost while merging hotfix_7.0 with master), so I undid the commit. However, something then went wrong.

Branch update_4.0 consists of:

application/modules/bookings/controllers/inspector.php
application/modules/bookings/models/data_bookings.php
application/modules/bookings/views/users/administrators/bookings/adjust.php
application/modules/invoices/controllers/invoices.php
application/modules/invoices/views/manage.php
application/modules/search/controllers/assets/invoices.php
application/modules/search/models/data_search.php

Branch hotfix_7.0 consists of:

application/modules/bookings/controllers/bookings.php
application/modules/bookings/controllers/inspector.php
application/modules/search/models/data_search.php
application/modules/venues/models/data_venues.php

When I switch to update_4.0, there are no files pending a commit, and the same for hotfix_7.0. But when I switch to master, the files for update_4.0 appear as pending a commit. Why? And — more importantly — what am I supposed to do next, to remediate this?

Update: based on the request of @twalberg, here's the branch structure data:

* 869e2f1 (HEAD, origin/hotfix_7.0, master, hotfix_7.0) An adjustment to the Search
| * c1e4c04 (update_4.0) Adjustments to Bookings, Invoicing, and Search
|/  
* d2413f9 (origin/master, update_3.0) Update an Invoice PDF
* 6a77f1e (hotfix_6.0) General fixes
* fb04b7e (update_2.0) Advanced Search
* c8222fe (hotfix_5.0) Caching
* 3baea6a (feature_5.0) Caching
| *-.   5c08c19 (refs/stash) On hotfix_4.0: GitHub: stashing before switching branches.
| |\ \  
|/ / /  
| | * 9a6cd92 untracked files on hotfix_4.0: 0ed797b Invoice date range
| * e7e4bbd index on hotfix_4.0: 0ed797b Invoice date range
|/  
* 0ed797b (hotfix_4.0) Invoice date range
* 4d9640d (hotfix_3.0) A fix to one of the search functions database methods, and the incl
* 8ee9f92 (feature_4.0) Users can now switch between Clients from anywhere in the system w
* 8d8752a (feature_3.0) In an effort to improve the invoicing process, I've made several a
* 2cff420 (hotfix_2.0) Switching references to the Commission for Venues column in Invoici
* 2403093 (feature_2.0) Statuses for Signatures, which allows the User to filter them in m
* 6572680 (hotfix_1.0) A conditional statement was checking against a string value as if i
* 6705899 (update_1.0) Alphabetical listing of Signatures for messages.
* 283bde4 (feature_1.0) Ability to edit group options in addition to group privileges for 
* 79ded64 To Book 3

Update: based on the request of @Ilion, here's the branch structure data:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   application/modules/bookings/controllers/inspector.php
#   modified:   application/modules/bookings/models/data_bookings.php
#   modified:   application/modules/bookings/views/users/administrators/bookings/adjust.php
#   modified:   application/modules/invoices/controllers/invoices.php
#   modified:   application/modules/invoices/views/manage.php
#   modified:   application/modules/search/controllers/assets/invoices.php
#   modified:   application/modules/search/models/data_search.php

As for why, I have seen this behavior with submodule folders -- change to a branch that does not have them and they are not removed -- but I would not expect someone new to git to be using submodules. This would just show the submodule folder in any event, not the files within the submodule.

The immediate answer to your second question, if you don't want the changes, you can get rid of them with the below commands.

If the files pending a commit are cached in the index (like they would be after git add . , you can remove them from the index with:

git rm -r --cached .

if they are not indexed, you can get rid of them for good with the following, which at times will need to be run twice (such as when the first removes a .gitignore file).

git clean -fd

A more long-term answer of what to do next depends on where you want to end up. We can see the commits and branches in your log output, and from your post it is not the way you want it. So, how do you want it to be?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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