Git 入门案例 本地文件上传到远程仓库

以管理员身份打开命令提示符

1.新建目录
d:
cd c:\
c:\>mkdir webapp1
 
2.进入目录
cd webapp1
c:\webapp1>
 
3.git初始化
git init
Initialized empty Git repository in C:/webapp1/.git/
初始化空的git仓库,路径为:…
 
4.新建一个文件index.html,在文件中写点代码
 
5.把文件加到仓库
git add index.html
git add . (一下子加多个)
 
6.提交到仓库
git commit -m '第一次提交'
 
报错了:
*** Please tell me who you are.
 
Run
 
  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"
 
to set your account's default identity.
Omit --global to set the identity only in this repository.
 
fatal: unable to auto-detect email address (got 'prime-rzq@DESKTOP-8N0BNT2.(none)')
 
7.配置
  git config --global user.email "[email protected]"
  git config --global user.name "prime-rzq"
8.重新提交
c:\webapp1>git commit -m '第一次提交'
[master (root-commit) d8ec367] '第一次提交'
 1 file changed, 11 insertions(+)
 create mode 100644 index.html
 
9.创建一个分枝b1
git branch
git branch b1
 
c:\webapp1>git branch
* master
 
c:\webapp1>git branch
  b1
* master
 
10.切换到b1分枝
git switch b1
 
c:\webapp1>git switch b1
Switched to branch 'b1'
 
c:\webapp1>git branch
* b1
  master
 
11. 改文件,建文件
Index.html里改了一点东西,新建了b2.txt
 
12.提交刚才的改动
git add .
git commit -m "改了index.html, 加了b2.txt"
 
c:\webapp1>git commit -m "改了index.html, 加了b2.txt"
[b1 a312cc3] 改了index.html, 加了b2.txt
 3 files changed, 2 insertions(+)
 create mode 100644 b2.txt
 create mode 100644 git
 
13.假设要回到master分枝
git switch master
b2.txt文件不见了,index.html恢复成原来的样子

14.查看暂存状态
`$ git status`

猜你喜欢

转载自blog.csdn.net/weixin_46622106/article/details/110859527