Git dividing branch

I am new to GIT, although I understand this concept. I don’t think I understand that either.

I was given the uitest branch for work, because I might not have performed push, commit, pull correctly, now I rejected the branch.

Since I'm new here, I also don't want to redefine other developer codes, as my code or changes are just experimental to get used to git and how it works. I would not refuse to change my changes, because I have a copy of everything I need to do everything.

 $ git status # On branch uitest # Your branch and 'origin/uitest' have diverged, # and have 47 and 6 different commits each, respectively. # nothing to commit (working directory clean) 

How can i break up? discard my changes and pull the latest changes from the latest changes, and then continue to work without disrupting the work of other peoples.

Also, since I am new to this, describe my answer a bit, as it may not make much sense to me.

Thank you very much

+4
source share
1 answer

There are several ways.

Combine

Firstly, you can simply combine origin/uitest , but that leaves no clear story in that it introduces what looks like a branch and a merge, although it should have been the same branch. I believe that Linus liked to call such a merger "meaningless." Unfortunately, this is also the easiest approach.

Rebase

Rebasing tends to be a more complex topic and can introduce a host of other problems if you are not careful. However, it is also a great way to get a clean story without meaningless commits. In this case, you can do:

 git rebase origin/uitest 

from your uitest branch, and that will take all the work you have done, and put it on top of the work in / uitest origin.

However, there are a couple of catches. Firstly, if you merged other branches into your branch, git rebase will reset them. You need to pass the -p flag so that all merges are not entered by you, but this is not always correct. If all you have done is make your own changes, you should be fine with the team I gave.

Secondly, whenever you use rebase, you should always remember to never re-establish public commits. Rebase will change commit identifiers because parents have changed. If people merge, you work, and you reinstall it, as a result, you will have several copies of your commits in history - this is bad. Therefore, be careful when applying this technique.

All that said is you want to make git rebase your friend. This is a powerful and useful tool, but, like any tool, it can be dangerous.

Cancel your work

If you just want to discard what you did, you can run:

 git reset --hard @{u} 

or

 git reset --hard origin/uitest 

This will reset your uitest branch to match the ascendant or origin/uitest . It will cancel your commits.

Personally, I re-install the work, or at least give it a try. If it fails or becomes complicated from merge conflicts, you can always abort with git rebase --abort and then return to merge or undo the changes (although merging will probably show you the same merge conflicts).

+4
source

All Articles