• 【Git学习】git 特殊命令


    git 的本地版本管理有三个部分

    名称 说明
    工作区(Working Directory) 我们直接编辑的文件部分
    暂存区(Staged Snapshot) 文件执行 git add .后存的地方
    版本库区 (Commit History) 文件执行 git commit .后存的地方

    Git 全局设置

    git config --global user.name "小明44356"
    git config --global user.email "44356@test.com"

    创建新版本库

    git clone git@code.test.org:test/test/test.git
    cd test
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master

    已存在的文件夹

    cd existing_folder
    git init
    git remote add origin git@code.test.org:test/test/test.git
    git add .
    git commit -m "Initial commit"
    git push -u origin master

    已存在的 Git 版本库

    cd existing_repo
    git remote rename origin old-origin
    git remote add origin git@code.test.org:test/test/test.git
    git push -u origin --all
    git push -u origin --tags

    Git强制覆盖

    git fetch --all
    git reset --hard origin/master
    git pull

    回退版本

    git reset --hard 版本号

    清除未跟踪文件

    git clean n //这个是清除文件预览

    git clean -f //强制清除文件

    强制切换分支

    git checkout -f <branch>

    强制推送本地代码到远程仓库

    git push origin master --force

    环境变量

    替换环境变量

    git config --global --replace-all user.name "你的 git 的名称" 

    git config --global --replace-all uesr.email "你的 git 的邮箱"

    删除环境变量

    1.查看Git所有配置

    git config --list

    git config --global -l

    git config --system -l    

    2.删除全局配置项

    (1)终端执行命令:

    git config --global --unset user.name

    (2)编辑配置文件:

    git config --global --edit

    **如果删除不掉,检查工程目录下.git/config  是否有私有变量,删除即可

    git合并出现冲突

    Your local changes to the following files would be overwritten by merge:
    Please, commit your changes or stash them before you can merge.
    解决方案:
    git stash //使返回到自己上一个commit,先隐藏
    git pull origin master //拉取最新的代码
    git stash pop //回到自己修改的代码

    作者:gtea 博客地址:https://www.cnblogs.com/gtea
  • 相关阅读:
    cygwin mysql forget root password
    emacs 复制粘贴的正确姿势
    yarn
    mysql 和 postgresql 区别
    hdfs
    spark
    hbase
    kafka
    flume
    java jar
  • 原文地址:https://www.cnblogs.com/gtea/p/13131253.html
Copyright © 2020-2023  润新知