Git - How can I pull and merge with my uncontrollable changes?

While working with some uncommitted files, I need to output new code. There is a conflict, so git refuses to pull:

error: Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge. 

Question 1: How can I pull and merge with my unstated changes? I need to keep working, I'm not ready to commit, but do I need external code?

Question 2: I ended up doing stash and then pull . How am I now merging in my changes with a new movement? How to apply my wallet without breaking new changes of attraction?

+5
source share
3 answers

Using stash , then pull , the last stash pop .

 git stash git pull git stash pop 
+10
source

Before delving into the mergers, I must draw your attention to the fact that there are two similar solutions for the "get the latest changes from the remote" task. For more info see git drag and drop VS git fetch git rebase . I prefer rebase, as it does not create redundant commits.

Do not be afraid to commit. You can easily do anything with it (change it with git commit --amend , drop it and put all the changes in worktree with git reset HEAD~1 ) until you push it somewhere.

Answer 1

 git add . # stage all changes for commit git commit -m 'Tmp' # make temporary commit git fetch $RemoteName # fetch new changes from remote git rebase $RemoteName/$BranchName # rebase my current working branch # (with temporary commit) on top of fethed changes git reset HEAD~1 # discard last commit # and pop all changes from it into worktree 

Answer 2

 git stash pop # this retrieves your changes # from last stash and put them as changes in worktree 

This command does not affect the commits that you receive using any command from the fetch family ( fetch , pull , ...).

+1
source

Git provides excellent documentation of their features. For this case, you will need a stack, you can see a few examples: https://git-scm.com/book/en/v1/Git-Tools-Stashing

-1
source

Source: https://habr.com/ru/post/1235261/


All Articles