刚开始用git
在自测的过程中遇到一个问题、就是如果是add的新文件在commit的时候可以不用指定文件直接提交
但是如果更新单个文件再去提交、就必须指定文件名才能commit成功提交、有遇到过么
你试试重新初始化和add,然后再commit,如下:
git init .
git add .
git commit -m "xxx"
通常:git commit 都不指定文件,而是-m添加提交信息。
add通常有如下两种。
# 添加git.py到暂存区
git add git.py
# 添加所有已修改代码到暂存区
git add .
commit如下。
# 提交代码
git commit -m "add print**"
参考:Git 代码管理(代码提交和代码回退)
如果不能正常使用,建议你重装git,并重新新建代码仓库。
$ vi README
给README文件新增一行内容“second”
再次变更文件后,git status状态;
PS E:\Python_project\gittest> git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
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: README
no changes added to commit (use "git add" and/or "git commit -a")
直接使用git commit -a跳过暂存区,直接提交到本地仓库;git status状态
PS E:\Python_project\gittest> git commit -a -m 'add a sentense(2)'
warning: LF will be replaced by CRLF in README.
The file will have its original line endings in your working directory
[master dce755f] add a sentense(2)
1 file changed, 1 insertion(+), 1 deletion(-)
PS E:\Python_project\gittest> git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
add 的操作是吧有变更的文件添加到文件暂存区,可以指定变更的文件,或者直接add . 表示所有,
commit 的操作是把暂存区的代码上传到远程仓库, -m “xxxx” ,xxx是自己填写的变更内容, 可以为空