7. git生命周期
7. git生命周期¶
1.未跟踪状态¶
[root@chupeng git03]# touch a_v2 b_v2
[root@chupeng git03]# ls
a_v1 a_v2 b_v2 c_v1
[root@chupeng git03]# git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a_v2
# b_v2
nothing added to commit but untracked files present (use "git add" to track)
2.跟踪状态¶
[root@chupeng git03]# git add a_v2 b_v2
[root@chupeng git03]# ls
a_v1 a_v2 b_v2 c_v1
[root@chupeng git03]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: a_v2
# new file: b_v2
#
3.提交¶
[root@chupeng git03]# git commit -m "第三次提交"
[master 114ca40] 第三次提交
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a_v2
create mode 100644 b_v2
You have new mail in /var/spool/mail/root
[root@chupeng git03]# git status
# On branch master
nothing to commit, working directory clean
4.修改文件,变成修改状态¶
[root@chupeng git03]# echo '222222' >b_v2
[root@chupeng git03]# cat b_v2
222222
[root@chupeng git03]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: b_v2
#
no changes added to commit (use "git add" and/or "git commit -a")
5.追踪¶
[root@chupeng git03]# git add b_v2
[root@chupeng git03]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: b_v2
#
6.提交¶
[root@chupeng git03]# git commit -m "第四次提交"
[master 435af0c] 第四次提交
1 file changed, 1 insertion(+)
[root@chupeng git03]# git status
# On branch master
nothing to commit, working directory clean
7.删除某个文件的跟踪¶
[root@chupeng git03]# git rm --cached c_v1
rm 'c_v1'
[root@chupeng git03]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: c_v1
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# c_v1
7.1 可以撤销刚才的动作¶
[root@chupeng git03]# git reset HEAD c_v1
[root@chupeng git03]# git status
# On branch master
nothing to commit, working directory clean
也可以再次跟踪
[root@chupeng git03]# git rm --cached c_v1
rm 'c_v1'
[root@chupeng git03]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: c_v1
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# c_v1
[root@chupeng git03]# git add c_v1
[root@chupeng git03]# git status
# On branch master
nothing to commit, working directory clean
7.2 还可以直接删除此文件¶
[root@chupeng git03]# git rm --cached c_v1
rm 'c_v1'
[root@chupeng git03]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: c_v1
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# c_v1
[root@chupeng git03]# rm c_v1
[root@chupeng git03]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: c_v1
#
最后更新:
2022-02-18 11:26:47