Several functions for one branch - what point?

In SourceTree, I have one branch called "develop". I am using SourceTree Git Flow to create a new function from the "develop" branch. I make changes to the function branch, and then end the function, and the changes revert to my "development" branch.

Then press these changes on the remote control.

Now, here is what I tried to do. At the same time, I had to work on two JIRA tasks. Therefore, I created two function branches from the "developed" branch: "develop / feature1" and "develop / feature2". I can switch between functions by double-clicking on them when selecting in SourceTree. Then I can check the working copy for both branches of the functions, but I noticed that the files that I added to one were also added to the other.

My questions:

  • When I add files to one working copy of a function, why do they appear in another working copy of the function?

  • What is the point of having function branches if they cannot isolate changes from each other?

+8
git git-checkout branch atlassian-sourcetree git-flow
source share
2 answers

git allows you to switch between branches even if you have uncommitted changes in the current branch. Files remain uncommitted and you can transfer them to another branch if you need to. This is great when you realize that you have done work on feature/feature1 , which should be on feature/feature2 .

After you make the changes, they no longer switch between branches. Then you can combine or change the cherry between the branches.

Please note that git will not allow you to switch between branches if you have uncommitted changes that cause merge conflicts in the branch you want to switch to, and possibly even if one of your changes is in the file that was changed and passed to the branch you want to go to. In this case, you first need to commit, revert, or reschedule your changes.

If git does not allow you to switch between branches, and you are trying to resolve this by putting your changes before switching branches, you must make sure that you are nested in the original branch. If you are on feature/feature1 , discard changes, then switch to feature/feature2 and put there, you will lose the changes that were present in feature/feature2 , but not in feature/feature1 . This is hard to detect.

+9
source share

New files and changes are not tracked by git until you run git add . This means that git does not have a copy of this data, therefore, if you returned your changes when checking another branch, they would not be able to restore them later.

You can see which files are indexed , modified, and without a trace with git status .

The only way to solve this problem is to track your changes with git, either by adding and fixing them (which you can undo later with git reset ), or by stamping them with git stash -u 1 (which you can undo later with git stash pop ).

The advantage of git working this way is that you can work on anything without thinking about branches. When the time comes for fixing, you can simply check the corresponding branch and add the necessary files with git add or add only those parts of the files that you want with git add -p .


1: -u is short for --include-untracked , which includes newly created files but not ignored files

+3
source share

All Articles