Git入门命令行的使用

git clone    复制远程仓库
git status   查看状态
git add      添加要提交到本地的代码
git commit   提交到本地仓库
git push     推送到远程
拉代码用到的
git fetch + git merge  //比较温柔的拉
git pull               //比较暴力的拉
git fetch + git merge  == git pull  //等价于  用命令行时建议用比较温柔的方式
julie@JULIE MINGW64 /c/repo
$ git clone https://gitee.com/sunjulie/Git-demo.git  //复制网址,下一步先修改.md里面的内容,再输入cd Git-demo/ 
Cloning into 'Git-demo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

julie@JULIE MINGW64 /c/repo
$ cd Git-demo/                                    //进入

julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git status                                     //查询状态
On branch master
Your branch is up to date with 'origin/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:   README.md                     //会变红色

no changes added to commit (use "git add" and/or "git commit -a")

julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git add README.md

julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   README.md                     //会变绿色


julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git commit -m "第一次提交"                     //-m"" 表示你对它做的标记,方便以后修改查阅
[master 197e4b2] 第一次提交
 1 file changed, 2 insertions(+), 1 deletion(-)

julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git push                                              //一般需要输入Git账号密码
Counting objects: 3, done.
Writing objects: 100% (3/3), 287 bytes | 95.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://gitee.com/sunjulie/Git-demo.git
   46e4977..197e4b2  master -> master

julie@JULIE MINGW64 /c/repo/Git-demo (master)        //去Git上查询发现已经被修改并传到服务器上去了
$

当别人把你的代码修改后和你的本地修改发生冲突时

julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git pull                                              //暴力强拉,不建议使用
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://gitee.com/sunjulie/Git-demo
   197e4b2..14e4973  master     -> origin/master
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

julie@JULIE MINGW64 /c/repo/Git-demo (master|MERGING)
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

julie@JULIE MINGW64 /c/repo/Git-demo (master|MERGING)
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

julie@JULIE MINGW64 /c/repo/Git-demo (master|MERGING)
$ git add README.md                                          //输入之前修改整合代码,最好和别人商量一下

julie@JULIE MINGW64 /c/repo/Git-demo (master|MERGING)
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

        modified:   README.md


julie@JULIE MINGW64 /c/repo/Git-demo (master|MERGING)
$ git commit -m "解决冲突"
[master 94d924f] 解决冲突

julie@JULIE MINGW64 /c/repo/Git-demo (master)
$ git push
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 597 bytes | 85.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://gitee.com/sunjulie/Git-demo.git
   14e4973..94d924f  master -> master
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值