- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对使用 Git 比较陌生。这是我到目前为止所做的:
$ 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")
现在,如果我切换到我的另一个分支,我希望我的更改保留在这个分支内。但是,看起来这些变化是随我而来的:
$ 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")
我做错了什么吗?还是我误解了我对 Git 的使用?
最佳答案
您的工作目录和您的存储库彼此分离,因为您的工作目录中的代码在提交之前不会与分支关联。
为了进一步搅浑水,git 引入了一个称为索引的新概念,它是工作目录和存储库之间的中转站。当您对一个文件运行 git add
时,您真正所做的是将它添加到索引中。同样,当您运行 git commit
时,您最终会将索引的内容添加到存储库中。
git status
区分索引和工作目录如下。
Changes to be committed:
表示索引的变化已更改但未更新:
表示工作目录中的文件已添加到存储库(且随后未被忽略)的更改未跟踪的文件:
表示工作目录中未已添加到存储库的文件的更改如果您有一些想要暂时保存的更改,但不保证它们有自己的分支,请使用 git stash
.这是 git 用于创建极其轻量级的单一提交分支的机制。来自man page (重点是我的):
Use
git stash
when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match theHEAD
commit.
关于Git:更改不应该留在他们的分支内吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6286539/
这是我的jade雕像: section#entry-review-template.template(data-class='entry-review') table thead
我是一名优秀的程序员,十分优秀!