简体   繁体   中英

Losing changes when using git merge

I'm somewhat new to git and I'm experiencing some unexpected results when I git merge . It appears that branch I'm merging FROM is changing, and this is not my understanding of how it should work.

Here's an example. I have two branches: master and new-branch. new-branch is ahead of master by several commits. Maybe I switch back to master to make a quick fix. Then I switch back to new-branch and I want that same fix from master to be applied. So (while in new-branch) I do:

git merge master

Now, should master have changed at all? I'm expecting only the changes from master to get applied to new-branch, but that doesn't seem to be happening. I keep loosing work and having to redo it and I cannot figure out why. Any advice?

Here's some git log :

ESL-MAC:sow3.dev $ git log
commit d30a517211c8663ab5cd28664d1b7ea59c82b248
Author: el
Date:   Fri Jan 11 17:18:44 2013 -0500

    fixed wsat page again

commit 31557a867585ac81b6fda33971d9ba16f1efafb9
Merge: 35af780 5ea9b23
Author: el
Date:   Fri Jan 11 17:10:22 2013 -0500

    replaced meta for get_wsat() in WSAT

commit 5ea9b233fb3d01c0dc9dfb5b0e48c80e8fb0eb58
Author: el
Date:   Fri Jan 11 16:50:06 2013 -0500

    removed admin bar AGAIN

commit 177d9ab8973c0e9f85a21ffad4ef6065cf6e9675
Author: el
Date:   Fri Jan 11 16:47:07 2013 -0500

:

This much is certain. In git if you:

git checkout new-branch

...and then...

git merge master

...nothing on master should change. As I think you already know, you're asking git to merge any new commits from master into new-branch . If you're getting a different result, something is seriously wrong. Hard to know what, though as you say you're new to git my best guess is that you're not actually committing on master the way you think you are.

The simplest process for a commit would be:

Do some work...

git add path-to-file(s)
git status (not strictly necessary, but will confirm that you actually added what you think you added)
git commit -m "This commits the file(s) I just added"

As Edward notes, seeing a git log might be revealing.

HTH!

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