Git 为什么不';t更改是否自动进入临时区域?
我使用某种版本控制-Git,我使用GitLab 据我所知,它对我来说是这样的: 当我创建一个新文件时——默认情况下,它在工作目录中。 为了将其移动到暂存区,我必须键入:Git 为什么不';t更改是否自动进入临时区域?,git,git-bash,Git,Git Bash,我使用某种版本控制-Git,我使用GitLab 据我所知,它对我来说是这样的: 当我创建一个新文件时——默认情况下,它在工作目录中。 为了将其移动到暂存区,我必须键入: git add 之后,为了将这些更改移动到本地存储库,我必须通过以下方式提交更改: git提交-m. 但是,当我处理现有文件时,它会自动位于暂存区域,并且在我更改文件之后;为了将更改移动到本地存储库,我只需通过 git提交-m 我按照这个理论工作,一切都很好 在某个时刻,我关闭了包括Git在内的笔记本电脑 一段时间后,我打开了G
git add
之后,为了将这些更改移动到本地存储库,我必须通过以下方式提交更改:
git提交-m.
但是,当我处理现有文件时,它会自动位于暂存区域,并且在我更改文件之后;为了将更改移动到本地存储库,我只需通过
git提交-m
我按照这个理论工作,一切都很好
在某个时刻,我关闭了包括Git在内的笔记本电脑一段时间后,我打开了Git bash;从那时起,它就不再对我起作用了 当我更改一个现有文件时,然后我尝试通过
git commit
提交更改;
我得到这个输出:分支主机上的
您的分支机构是最新的“来源/主”。
未为提交而暂存的更改:
修改:文件_0.txt
未添加任何更改以提交
这意味着我还没有准备好改变。但是,我不必准备退出文件 有人有想法吗?
提前感谢您的帮助 但是,当我处理现有文件时,它会自动位于暂存区域,并且在我更改文件之后;为了将更改移动到本地存储库,我只需通过git commit-m提交更改 Git不是这样工作的。必须将更改添加到临时区域,即使是现有(跟踪)文件。要么您使用的是
git commit-a-m
,要么您有一个自动添加更改的工具
git add
做两件事。它将文件标记为正在跟踪,并将跟踪的文件复制到临时区域
新文件未被跟踪。未跟踪的文件不被视为Git存储库的一部分。它们不会使用诸如git commit-a
之类的命令添加到临时区域
$ git add this
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: this
$ git commit -a -m 'commit this'
[master (root-commit) 519fada] commit this
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 this
$ echo 'something new' > this
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: this
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -a -m 'commit more of this'
[master 996ddb2] commit more of this
1 file changed, 1 insertion(+)
-a、 --全部
告诉命令自动暂存已修改和删除的文件,但未告知Git的新文件不受影响
您可以使用git add--intent to add
将文件设置为跟踪,但不添加更改
使用git add-u
只能将跟踪的文件复制到声明区域
$ touch that
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
nothing added to commit but untracked files present (use "git add" to track)
$ echo 'another line' >> this
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: this
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -u
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: this
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
$touch
$git状态
论分行行长
未跟踪的文件:
(使用“git add…”包含在将提交的内容中)
那个
提交时未添加任何内容,但存在未跟踪的文件(使用“git add”跟踪)
$echo“另一行”>>此
$git状态
论分行行长
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git restore…”放弃工作目录中的更改)
修改:这个
未跟踪的文件:
(使用“git add…”包含在将提交的内容中)
那个
未向提交添加任何更改(使用“git add”和/或“git commit-a”)
$git添加-u
$git状态
论分行行长
要提交的更改:
(使用“git还原--暂存…”取消暂存)
修改:这个
未跟踪的文件:
(使用“git add…”包含在将提交的内容中)
那个
但是,当我处理现有文件时,它会自动位于暂存区域?
原始文件是,更改不是。您确定吗?我在Git上工作了很长一段时间,在处理现有文件的方式上,我只是提交并推送了它们。我确信。如果您从不需要将它们添加到暂存区域,那么要么您的IDE为您这样做,要么您使用a
选项来git commit
。
$ touch that
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
nothing added to commit but untracked files present (use "git add" to track)
$ echo 'another line' >> this
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: this
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -u
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: this
Untracked files:
(use "git add <file>..." to include in what will be committed)
that