下载
1.去别人github项目页面得到git地址
https://github.com/hiudawn/ml_in_action.git
2.使用git工具(windows需要下载git,linux直接用git命令即可)
先切换到要保存的目录,执行类似下面这句即可
git clone https://github.com/hiudawn/ml_in_action.git
初次上传
1.在github.com上创建一个仓库,得到自己的git地址
https://github.com/hiudawn/ml_in_action.git
2.打开git,在本地cd 到你要提交的那个目录下
3.初始化本地仓库
git init
4.添加目录下所有文件到提交列表
git add .
5.配置个人信息
git config --global user.email "you@example.com"
git config --global user.name "yourname"
6.本地提交(未到远程)
git commit -m "first commit"
7.添加远程仓库(第一步得到的链接地址)
git remote add origin https://github.com/hiudawn/ml_in_action.git
8.提交到远程
git push -u origin master
# 这里需要输入你github的帐号和密码
上一步可能会报错:
$ git push -u origin master
To https://github.com/hiudawn/ml_in_action.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/hiudawn/ml_in_action.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
有概率是本地没有同步README.md文件,用下面这句合并一下
git pull --rebase origin master
再次提交
git push -u origin master
一般会成功
更新上传
1.可以查看一下文件的更新情况
git status
2.更新文件夹所有文件
git add .
3.提交列表
git commit -m "关于更新的说明"
4.提交到远程
git push origin master
强制覆盖
git fetch --all # 取不一样的东西
git reset --hard origin/master # master可以改为想要分支
git pull # 拉取远程代码
免密
1.linux下,密码会以明文形式保存在~/.git-credentials,这个store还可以设置成cache,就是保存在内存一段时间
git config --global credential.helper store
恢复reset --hard文件
# 撤销commit
git log
# 撤销删除或回滚
git relog
然后
git reset --hard xxxid
错误
$ git clone https://github.com/tensorlayer/srgan.git
Cloning into 'srgan'...
fatal: I don't handle protocol 'https'
把clone后面的空白字符删掉