git - nonelittlesong/study-ubuntu GitHub Wiki

参考:

git配置ssh

https://help.github.com/articles/checking-for-existing-ssh-keys/

git操作

git status -s

git commit -a -v

  • -a: 给 git commit 加上 -a 选项,Git 就会自动把所有已经跟踪过的文件暂存起来一并提交,从而跳过 git add 步骤;
  • -v: 如果想要更详细的对修改了哪些内容的提示,可以用 -v 选项,这会将你所做的改变的 diff 输出放到编辑器中从而使你知道本次提交具体做了哪些修改。

git rm --cached

  • --cached: 想让文件保留在磁盘,但是并不想让 Git 继续跟踪。

撤销

  • git commit --amend
  • git reset HEAD <file>...
  • git checkout -- <file>...

添加远程仓库

  • git remote add <shortname> <url>
  • git fetch <remote-name>

推送到远程仓库

git push [remote-name] [branch-name]
只有当你有所克隆服务器的写入权限,并且之前没有人推送过时,这条命令才能生效。
你必须先将他们的工作拉取下来并将其合并进你的工作后才能推送。

troubleshooting

clone fail

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

原因:网太差
解决方法一:
一般clone http容易出现此问题,改用SSH方式,即https://改为git://
解决方法二:
The idea is to do a shallow clone first and then update the repository with its history.

$ git clone http://github.com/large-repository --depth 1
$ cd large-repository
$ git fetch --unshallow
⚠️ **GitHub.com Fallback** ⚠️