Associated with the work area to modify the file with git branch

Original link: http://www.cnblogs.com/cynthia0705/p/3397059.html

    The following analysis with examples, assuming that there is now a code repository, which has two branches master and test, the state of the two branches of the same, have already submitted a file 11.txt, document reads as follows:

   11111111111
   hhaa

Now we cut to the master branch, add a line of characters in the end of the file 11.txt

  do the best

And then view the status git repository with git status, as shown in FIG.

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   11.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

He expressed the need to modify the workspace file 11.txt added to the staging area and submit.

In this case the first of these operations is not switched directly to the test branch, and then view the status, print information found to be identical with the above. And I did not make changes to 11.txt files on the test branch, which is what causes it?

If this is the case, the operation execution command git add 11.txt, added to the staging area, and then check the status of execution git status, two branches discovery state remains in the same branch or master test

Prints are

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   11.txt
#

Switch back to the master branch,

git commit -m " ”

Submitted in the master branch on 11.txt file. On the master branch and test execution branches git status to view the status, print as follows

# On branch test
nothing to commit (working directory clean)

Description workspace is clean, there are no documents submitted.

At this view by git log or gitk, we found more than a submission under the master branch, and when to switch to the test to see above and found that the above test is no new submissions.

On the other hand, if it is to perform operations in the test git commit branch, the branch will then test this new submission, but no master above.

 

 

After the note above these operations, we are all carried out under the same content 11.txt files on two branches, the above operation finished, the master branch 11.txt files already on the test than the branch file to ahead,

At this point if you switch to the master branch, and then add new content end of the file:

   11111111111
   hhaa 

   do the best

   good

After the local preservation, not git add, also did not submit, they attempt to switch branches to test above,

git checkout test
error: You have local changes to '11.txt'; cannot switch branches.

If after git add 11.txt, has not been submitted, it will switch branches,

git checkout test
error: Entry '11.txt' would be overwritten by merge. Cannot merge.

Description git branch local workspace and the temporary file is modified global area management. If you submit a final 11.txt files on different branches inconsistent, we modify the local workspace, and to add to the staging, and the submission, all done on this branch, prior to submission can not switch to another branch . When the submission of a final 11.txt files on different branches of the same, git repository can also be identified, then regardless of the switch to make changes and additions to the staging area in the work area on which branch, git repository did not directly these two operations with which a branch association, branch when we performed last git commit submission which is where, this time relationship is established, modified workspace, add the staging area and submission, is associated to it is performed on a branch.

Reproduced in: https: //www.cnblogs.com/cynthia0705/p/3397059.html

Guess you like

Origin blog.csdn.net/weixin_30633405/article/details/94784384