Git:不应该改变应该留在他们的分支? [英] Git: Aren't changes supposed to stay within their branch?

查看:126
本文介绍了Git:不应该改变应该留在他们的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Git比较新。这是我迄今为止所做的:

  $ git branch 
* master

$ git status
#在分支master上
没有提交(工作目录清理)

$ git分支mywork
$ git checkout mywork
$ git分支
* mywork
master

...修改一些文件...

$ git status
#分支mywork
#已更改但未更新:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - < file> ;. ..放弃工作目录中的更改)

#修改:file1.html
#修改:file2.html

没有更改添加到提交使用git add和/或git commit -a)

现在,如果我切换到我的其他分支,我希望我的更改留在这个分支。然而,它看起来像我的变化:

  $ git checkout master 
M file1.html
M file2.html
转换到分支'master'

$ git status
#分支主
#已更改但未更新:
#(使用git add< file> ...更新将要提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:file1.html
#修改:file2.html

没有更改添加到提交中(使用git add和/或git commit -a )

我做错了什么?或者我误解了我对Git的使用?

解决方案

在切换回主分支之前,您需要添加和提交更改
$ b 使用:

  git checkout mywork 
#修改文件

git add。 #将所有编辑的文件添加到存储库
git commit -m关于更改的消息

git checkout master

你可以在 The Git Book


I am relatively new to using Git. This is what I've done so far:

$ git branch
* master

$ git status
# On branch master
nothing to commit (working directory clean)

$ git branch mywork
$ git checkout mywork
$ git branch
* mywork
  master

...modify some files...

$ git status
# On branch mywork
# 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:   file1.html
#   modified:   file2.html
#
no changes added to commit (use "git add" and/or "git commit -a")

Now if I switch to my other branch, I expect my changes to stay within this branch. However, it looks like the changes come with me:

$ git checkout master
M   file1.html
M   file2.html
Switched to branch 'master'

$ git status
# 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:   file1.html
#   modified:   file2.html
#
no changes added to commit (use "git add" and/or "git commit -a")

Am I doing something wrong? Or am I misunderstanding my use of Git?

解决方案

Before switching back to your master branch, you need to add and commit your changes to the branch.

Use:

git checkout mywork
# Modify files

git add . # Adds all edited files to the repository
git commit -m "Message about the changes"

git checkout master

You can find lots of information about Git at The Git Book

这篇关于Git:不应该改变应该留在他们的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆