如何重新命名 (直接在文件系统上重命名)
- 添加一个新文件
git4.md
文件
-
git status
发现有新文件
-
git add .
添加到暂存区
-
git commit -m 'add git4.md'
提交到主目录
-
git status
再次查看当前状态
On branch master
nothing to commit, working tree clean
- 右键编辑
git4.md
文件,重新命名为 git5.md
-
git status
查看当前状态 (会提示当前删除了 git4.md
, 有一个git5.md
待添加)
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: git4.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
git5.md
no changes added to commit (use "git add" and/or "git commit -a")
-
git rm git4.md
当前命令是告诉工作目录,我已删除了git4.md
文件
-
git add git5.md
添加当前重新命名的文件
-
git status
查看状态(重命名git4.md
-> git5.md
)
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: git4.md -> git5.md
-
git commit -m '把git4.md文件重命名为git5.md'
提交更名的文件,并添加备注
-
git push origin master
提交到主分支 完成文件重新命名
使用 git mv
重命名
-
git mv git5.md git4.md
把 git5.md
重命名为 git4.md
git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: git5.md -> git4.md
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: git4.md
git commit -m '使用git mv 重新命名了git5.md'
[master a3b182d] 使用git mv 重新命名了git5.md
1 file changed, 0 insertions(+), 0 deletions(-)
rename git5.md => git4.md (100%)
使用 git mv
移动文件
-
mkdir md
创建一个文件夹
-
git mv git4.md md/
把 git4.md
移动到 md
目录下面
-
git status
提示一个重命名的文件(renamed
)
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: git4.md -> md/git4.md
git commit -m '把 git4.md 文件移动到 md文件夹里面'
-
mkdir asset
创建一个新文件夹
-
git mv md asset
把 md
文件夹移动到 asset
文件夹里面
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: md/git4.md -> asset/md/git4.md
网友评论