写完代码或是添加修改文件后,通过git status 命令查看
命令:git status
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$ git status ./
On branch develop
Your branch is up to date with 'origin/develop'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
ReadMe.md
nothing added to commit but untracked files present (use "git add" to track)
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$
把修改好的文件,通过git add 命令进行添加
命令:git add file //添加修改文件
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$ git add ReadMe.md
再次使用git status 命令查看file的状态
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$ git status ./
On branch develop
Your branch is up to date with 'origin/develop'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: ReadMe.md
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$
在执行git add 之后,需要执行git commit命令提交消息
命令:git commit -m "备注消息描述"
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$ git commit -m "closes #100,add file ReadMe.md"
===================msg================
closes #100,add file ReadMe.md
===================msg================
had input redmine issue #ID
[develop d1824c068] closes #100,add file ReadMe.md
1 file changed, 17 insertions(+)
create mode 100644 qcom/proprietary/commonsys/fastmmi/ReadMe.md
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi/$
倘若执行完commit后,想撤回commit,怎么办?可以通过如下命令进行撤销
命令:git reset --soft HEAD^
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$git reset --soft HEAD^
其中,
--soft
不删除工作空间改动代码,撤销commit,不撤销git add .
HEAD^的意思是上一个版本,也可以写成HEAD~1
如果你进行了2次commit,想都撤回,可以使用HEAD~2
如果commit注释写错了,只是想改一下注释,只需要:
命令:git commit --amend
此时会进入默认vim编辑器,修改注释完毕后wq保存就好了。
再次使用git status 命令查看file的状态
admin@software:~/workspace/sourcecode/vendor/qcom/proprietar/commonsys/fastmmi$ git status ./
On branch develop
Your branch is up to date with 'origin/develop'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: ReadMe.md
admin@software:~/workspace/sourcecode/vendor/qcom/proprietary/commonsys/fastmmi$
ReadMe.md 文件的状态又回到git add 之后的状态,这样就成功的撤销了你的commit
注意:仅仅是撤回commit操作,您写的代码仍然保留。