git日常汇总

用户名密码

git config --global user.name [username]
git config --global user.email [email]
# 关闭ssl验证
git config --global http.sslverify false

git查看远程地址

git remote -v

修改了两个文件a、b,假设需要撤销文件a的修改,则:

  1. 如果没有被git add到索引区
    git checkout a 便可撤销对文件a的修改
  2. 如果被git add到索引区,但没有做git commit提交
    1)使用git reset将a从索引区移除(但会保留在工作区)git reset HEAD a
    2)撤销工作区中文件a的修改git checkout a
  3. 如果已被提交,则需要先回退当前提交到工作区,然后撤销文件a的修改
    1)回退当前提交到工作区git reset HEAD^
    2)撤销工作区中文件a的修改git checkout a
  4. 补充:灵活使用以上操作的关键在于理解git中工作区、索引区的概念和git reset命令hard、mixed(default)、soft三种模式的区别,网上有很多这方面的文章,不再赘述。

Fork的别人分支,同步更新

git remote -v 
# 查看远程分支,如果只有两个origin的分支,说明没有建立远程的repo源
origin  https://gitlab.cn/beiertiao/my.git (fetch)
origin  https://gitlab.cn/beiertiao/my.git (push)
#添加远程repo
git remote add upstream https://gitlab.cn/admin/my.git
git morete -v 
#查看远程分支:
origin  https://gitlab.cn/beiertiao/my.git (fetch)
origin  https://gitlab.cn/beiertiao/my.git (push)
upstream        https://gitlab.cn/admin/my.git (fetch)
upstream        https://gitlab.cn/admin/my.git (push)
#获取远程代码
git fetch upstream
#merge本地分支,这个merge命令好奇怪哦
git merge upstream/master
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容