退出 git log
在英文状态下按 q
git clone 重命名
如何重命名仓库,对当前文件夹已经存在同名仓库的时候会很有用:
1  | git clone git@github.com:muwenzi/repo.git new-repo-name  | 
git rm
有时候在项目开发过程中,把某些目录或文件加入.gitignore后发现并未生效,原因是.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
1  | git rm -r --cached .  | 
.gitignore 的匹配规则:
1  | .a # 忽略所有 .a 结尾的文件  | 
更改 git commit 注释
git add . ,git commit -m "wrong explanatory" 之后还没有 git push , 发现 git commit 的注释写错了。
这个时候输入 git commit --amend,会自动打开 vim 编辑器,按 a 进入编辑模式,将正确的注释写入,然后按 ESC 键,输入 :wq 进行保存并退出,然后 git push。
github仓库更改名字后
1  | 更改github仓库名称后在本地进行git push出现下面提示,在这种情况下github也能同步  | 
查看当前名称
1  | git remote -v  | 
进行 set-url
1  | git remote set-url origin https://github.com/YOUR-USERNAME/YOUR-REPO.git  | 
修改后再查看,以后再进行 git push 就不会出现上面的提示了。
1  | git remote -v  |