I am relatively new to Git, and I'm still not very comfortable with it. Right now, I'm looking for the command/options/magic that can开发者_如何转开发 make the current branch look like another branch; that is, to merge them, but when a conflict arises, to always choose the difference in the branch that is being merged into the current one.
My situation is thus; I have an stable(ish) application on the "master" branch. I also have another branch, called "feature". I basically want to make changes/additions/deletions to feature until I like the new feature I'm working on. Once I feel it is ready, I want to make the master branch look identical to the feature branch.
I know this probably isn't a best practice, but as I said, I'm new to Git. I plan on learning how to do more complicated things in the future, but for now, this is all I need.
Thanks, SO!
The accepted answer ("Branches are just pointers ...") is no good for me, because not only do I need my branch to look like another branch - I need to do so by only adding commits (not losing any of the commits in the current history of my branch).
I liked this approach for making branch A
look like branch B
:
git checkout B
git diff A > patch_to_make_A_like_B
git checkout A
git apply patch_to_make_A_like_B
(And rm patch_to_make_A_like_B
at the end.)
Sorry! Didn't read all the way through before answering...
git checkout master
git merge feature
This will work effortlessly if you have not made any changes to master
since you branched feature
off it.
And what you are trying to do is exactly the way that branching and merging are supposed to work. Develop your features on a branch, when you have it stable and working like you want it to work, merge it back into the master branch.
I know this was asked awhile ago, and there are a few answers already, but I thought I would offer my 2 cents:
If you're looking to do a git merge
and you don't want to worry about merge conflicts (always prefer the changes in one branch over another), then you can use git merge branch -X ours
and git merge branch -X theirs
. There's more explanation on this in
https://stackoverflow.com/questions/13594344.
I would argue, however, that a git rebase
would make more sense here. Some pros/cons are on the Rebase vs. Merge page. The merge is intended to retain a history of events that transpired including the merge itself, but from the sound of your question it seems like you're only looking to keep track of the events in the application development, hiding the fact that you ever had a separate branch in the first place.
Branches are just pointers within the graph of commits. You can git-reset
a branch to point to anywhere you like, just make sure you checkout the intended branch before making any further commits.
精彩评论