Working on the same branch, how to pull without losing changes?

I am working on the same department as my colleagues. Now I have made some files and sent them to check the code, and I have another employee. Now he is pushing his code before I do this. Now I need to revert its changes, and then add the changes. But it has already been done.

How can I get its changes and then add my changes without a bad story and I have to jump hoops? I am new to git.

+4
source share
3 answers

You can use git pull --rebase. This will commit your peers and then add your commits (which you didn't click) on top of them, keeping a story that also looks good.

: . , , rebase, .

+6

, git pull --rebase, : , :

A -> B -> C -> D | | local master remote/master :

$ git branch save_state $ git reset --hard C

A -> B -> C (remote/master) \ -> D (local save_state)

,

$ git pull origin master

( ) ,

$ git checkout save_state $ git rebase master $ git checkout master && git merge save_state , .

+1
git pull

This will lead to its changes from a remote server, bring them locally to your computer, and then combine its work with yours. This will provide an opportunity to join the story: one branch with your work, one branch with it, and then a connection when they merge. Git will give you the ability to fix any conflicts if necessary, but it does a great job of auto-merging.

I highly recommend you read the following: https://git-scm.com/book/en/v2

0
source

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


All Articles