• Git常用命令举例


    clone一个git project到本地

    git clone https://github.com/huahuiyang/network-certification.git

    到这个目录下,可以发现有个隐藏文件夹.git

    cd network-certification/

    创建branch

    git branch mybranch

    在branch和master之间切换

    git checkout mybranch
    
    git checkout master

    配置git的账号名和邮箱

    git config --global user.name "huahuiyang"
    git config --global user.email "huahuiyang@gmail.com"

    切到branch,做些修改比如新建一个文件叫help,写点内容

    git checkout mybranch
    touch
    help echo "aaa" >> help

    把这个文件加到版本控制,在mybranch中提交

    git add help
    git commit -m "add help"

    删除某个文件

    git rm file
    git commit -m "del file"

    git状态查看

    git status

    当前处于哪个分支查看

    git branch

    然后准备把mybranch的修改merge回master,需要先切回主干

    git checkout master
    git merge mybranch

    然后可以向git总库提交修改

    git push

    本地创建了一个分支,要想向远程库提交这个分支,运行以下命令

    git push origin [name]

    如果git push回馈403错误,那就是密码输错了,如果没有提示输密码,如下操作,加上红色部分,告知账号,而后git push会提示输入密码

    vim .git/config
    
    [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = https://huahuiyang@github.com/huahuiyang/network-certification.git

    如果遇到如下错误:

    error: cannot open .git/FETCH_HEAD: Permission denied

    表明此时该用户没有权限,切换到有权限的账号,然后运行以下命令,youruser改成你的账号名称

    chown -R youruser .git   
    #修改用户
    git config --global user.name "Huahui Yang"
    git config --global user.email "huahui.yang@email.com"
    git commit --amend --reset-author
    
    #看本地log历史
    git log
    
    #回退到某个版本
    git reset --hard <commit-id>   
    #修改已经本地commit过的作者信息
    git checkout -b newbranch
    git log
    git rebase -i cccdd....
    #修改push为edit git rebase
    --continue;git commit --amend --author=huahui.yang@email.com --no-edit git push origin a:remote-branch-name git pull origin remote-branch-name git checkout remote-branch-name git branch -D a

    git reset HEAD file

    回滚git add操作

    git reset --soft commit_id

    回滚commit操作

    git add ..

    git commit ..

    git add ..

    git commit --amend

    合并成一个commit

    ok,大概常用的代码这些,enjoy!

  • 相关阅读:
    你可见过一种基于状压的二进制筛法?
    dp
    tricks
    csp2020 游记
    洛谷P2982 [USACO10FEB]慢下来Slowing down
    NOIP 2018 大翻车记
    2019 ICPC 南京网络赛
    POJ2778 AC自动机 + 快速矩阵幂
    2019 CCPC网络赛
    2018ICPC 北京
  • 原文地址:https://www.cnblogs.com/yanghuahui/p/3679435.html
Copyright © 2020-2023  润新知