github学习使用(三)

之前的都是在看书的基础上面,小大小闹,今儿咱就直接进行实际操作来搞定学习使用这个git工具。

1.就是在github上面建立一个文件夹,这里我建的文件夹叫practise。

这里github会给我生成一个ssh的url:git@github.com:chenbinghuilove/practise.git

这里需要我们通过clone将这个git文件给克隆到我们本地,

root@zhou:~/.ssh# ls
chentest  demo  helloword  id_rsa  id_rsa.pub  known_hosts  mytest
root@zhou:~/.ssh# git clone git@github.com:chenbinghuilove/practise.git
Cloning into 'practise'...
Enter passphrase for key '/root/.ssh/id_rsa': 
warning: You appear to have cloned an empty repository.
root@zhou:~/.ssh# ls
chentest  demo  helloword  id_rsa  id_rsa.pub  known_hosts  mytest  practise
这里直接就可以进入这个practise文件进行我们的操作了。这里我新建了一个test.sh的sh文件,里面的内容是

this is a test file
wo want to study this file
go on
然后,通过一下的操作,这里也是基本的规范的操作,随时关注我们的项目代码的状态。

root@zhou:~/.ssh# cd practise/
root@zhou:~/.ssh/practise# ls
root@zhou:~/.ssh/practise# vim test.sh
root@zhou:~/.ssh/practise# git status -s
?? test.sh
root@zhou:~/.ssh/practise# git add test.sh
root@zhou:~/.ssh/practise# git status -s
A  test.sh
这里我们可以看到有个
?? test.sh 这里的意思git不知道你的代码是否需要跟踪是个untracked状态,
A  test.sh 这里我们add操作后,就可以看到已经是在索引区(暂存区)中是一个add(添加状态)。接着继续看
root@zhou:~/.ssh/practise# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   test.sh
#
所有这里我们应该知道了,这时的test文件已经在暂存区内部了。

这里我们以选择修改和提交到版本库当中。这里是我测试的直接提交到github上面去了,这时就可以去github上面查看下是否存在。

root@zhou:~/.ssh/practise# git push origin master
Enter passphrase for key '/root/.ssh/id_rsa': 
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 252 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:chenbinghuilove/practise.git
 * [new branch]      master -> master
2.这里说明一点,当我们对本地文件进行修改了以后,我们必须重复以前的操作,也就是还要有提交add操作和commit操作

这里我又重新修改了这里的test的文件加入test again的文字信息

root@zhou:~/.ssh/practise# vim test.sh 
root@zhou:~/.ssh/practise# git status -s
A  name.sh
 M test.sh
看到的状态就是上面的,说明当地工作区的test文件是被修改状态了。我们所要做的就是重复之前的所有操作并且成功加入到github服务器中。

root@zhou:~/.ssh/practise# git add test.sh
root@zhou:~/.ssh/practise# git status -s
A  name.sh
M  test.sh
root@zhou:~/.ssh/practise# git commit -m "test again"
[master 5e6980c] test again
 2 files changed, 8 insertions(+)
 create mode 100644 name.sh
root@zhou:~/.ssh/practise# git status -s
root@zhou:~/.ssh/practise# 
这里可以看到了,我们的github服务器中也存在了我们的修改信息,这里有个问题可以看到了,我在commit的时候没有指定那个文件,那么所有文件就都被提交了,则可是非常危险了的。

3.删除文件一些操作说明

这里的做法就是首先删除当地工作区的文件,然后在删除暂存区的文件,最后再提交这个暂存区,并push的github上面去,这里要注意到status的各种状态。

root@zhou:~/.ssh/practise# rm name.sh 
root@zhou:~/.ssh/practise# git status
# 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:    name.sh
#
no changes added to commit (use "git add" and/or "git commit -a")
root@zhou:~/.ssh/practise# git status -s
 D name.sh
root@zhou:~/.ssh/practise# git rm name.sh
rm 'name.sh'
root@zhou:~/.ssh/practise# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	deleted:    name.sh
#
root@zhou:~/.ssh/practise# git status -s
D  name.sh
4.如果需要回滚到我以前的某个文件(可能修改了,可能删除了)
这里有点儿复杂,待我搞清楚了以后在来写吧










  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值