Pergunta

I'm using Git and I'm new to it. I have the latest code of a project, and I'm working on a new feature but while I'm working on that new feature I received an email of a fix I need that is commited but I do not have it yet. Unfortunately I can't 'get latest version' like with svn (and merge if needed) as the new feature file seem to be blocking the pull even if the new feature file are not common with the fix I need to get. What is the best way to do it for both scenario: 1) I have no common files modified with the new file I need, scenario 2) I have common file modified (I just want to do a quick local merge basically like with svn)? thanks w

Shall I stash, do a pull to get the fix, and continue to work on my feature? and pop the stash when I'm done?

Foi útil?

Solução

The original poster asks:

Shall I stash, do a pull to get the fix, and continue to work on my feature? and pop the stash when I'm done?

That's one option you have. The other options are as follows:

The original poster asks:

What is the best way to do it for both scenario:

  1. I have no common files modified with the new file I need?
  2. I have common file modified (I just want to do a quick local merge basically like with svn)?

If the new file you have is ready to commit, you can just commit it, then do a merge or a rebase. If the file you modified is also modified in the commits you're fetching, it doesn't really matter if you do a merge or a rebase, there's a chance that you might have to resolve conflicts either way:

git commit -am "Commit message here"
git fetch <remote-with-fix>

# Rebase your work on top of fix
git rebase <remote-with-fix>/<branch-with-fix>

# Or do a merge instead
git merge <remote-with-fix>/<branch-with-fix>

If the new file you have is not ready to commit, you could just make a temporary commit, then do a fetch of the fix, then rebase your work on top, then undo the temporary commit with a mixed reset:

git commit -am "Temporary commit"
git fetch <remote-with-fix>
git rebase <remote-with-fix>/<branch-with-fix>    
git reset head^

Outras dicas

If the branch with the fix has nothing else but the fix, then simply merge it.

If the branch has other stuff that you don't want in your current branch, then cherry-pick. Be careful with cherry-picking though, as that does not track the commit history as a real merge, which may cause conflicts later if you will ever merge these branches into one another.

I think yours is the first case. No need to overthink, just merge the branch, that's it.

If there are common files modified, you may get conflicts, which you will have to resolve manually.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top