• Git


    01 - 临时保存和恢复当前改动

    执行git stash保存后,git status将显示无任何改动。

    git stash  # Temporarily stores all modified tracked files
    
    git stash list  # Lists all stashed changesets
    git stash pop <stash> # Restores the stashed files, and delete the stashed files.
    git stash apply <stash> # Restores the stashed files, and reserve the stashed files.
    
    git stash drop  # Discards the most recently stashed changeset
    git stash show  # Show the latest changes recorded in the stash as a diff between the stashed state and its original parent. 
    git stash clear  # Remove all the stashed states. 
    

    02 - 推送失败

    不同的人修改同个文件的同一个地方,然后推送到远程库是会发生“推送失败”,因为推送有冲突。
    解决方法:先用git pull抓取最新的提交,然后在本地合并,解决冲突,再推送。
    使用git pull前,必须指定本地branch分支与远程origin/branch分支的链接(git branch --set-upstream-to

    03 - 多人协作

    尝试用git push origin <branch name>推送修改。
    如果推送失败,可能因为远程分支比本地更新早,使用git pull试图合并。
    如果合并有冲突,则需要解决冲突,并在本地提交,再用git push origin <branch name>推送。

    04 - 配置local repository

    Local配置优先级高于global配置,而且Local的配置必须在local repository目录下完成。
    示例:

    $ git config --local user.name "anliven"  # 配置local repository的用户名
    $ git config --local user.email "anliven@yeah.net"    # 配置local repository的邮箱
    
    $ git config --local --list # 显示local repository配置信息
    $ git config --local --unset [value-regex]  # 去除local repository配置
    
    $ git config --local --edit  # 交互式local repository配置
    

    05 - 配置文件

    Git配置文件优先级:local > global > system

    配置文件 有效范围 查看 配置方法 名称及目录
    local 本地仓库 git config --local --list git config --local --edit 本地仓库目录下,例如:<local repository>.gitconfig
    global 所有仓库 git config --global --list git config --global --edit 用户目录下,例如:C:Usersxxx.gitconfig
    system 不建议改动 git config --system --list git config --system --edit git的安装目录下,例如:C:Program FilesGitmingw64etcgitconfig

    06 - 合并多个commit

    利用git rebase -i把其它commits标注为squash,从而将其它commits并入一个commit。
    合并多个 Commit
    合并 commit 保持分支干净整洁

    07 - 命令执行

    • 注意git命令的执行目录、生效目录和执行结果中的目录信息
    • 利用tab键补全目录、文件和命令名称
    • 使用完整的git命令,便于理解和确认

    08 - 对比git pull和git pull --rebase

    link
    git pull = git fetch + git merge
    git pull --rebase = git fetch + git rebase

    09 - 修改文件权限

    # 在相应Repository目录中查看文件权限
    git ls-tree HEAD
    
    # 修改权限(权限修改后,相当于文件进入了index)
    git update-index --chmod=+x <test.sh>
    
    # 提交修改
    git commit -m "script permission update"
    
    # 确认修改结果
    git ls-tree HEAD
    

    10 - 报错:^M: bad interpreter

    检查文件格式,必要时使用dos2unix命令转换文件格式。
    在windows git下,建议关闭自动换行,并启用安全换行检查。

    # 关闭自动换行的设置
    git config --global core.autocrlf false
    
    # 启用安全换行符检查
    git config --global core.safecrlf true
    

    11 - Git添加空文件夹

    默认情况下,git将忽略空文件夹,也就是说空文件夹无法加入到repository。
    解决办法:在空文件夹下创建包含!.gitignore内容的.gitignore文件即可。

    12 - 从指定分支或提交检出单个文件

    git checkout <branch-name> -- <file-name>
    git checkout <commit-id> -- <file-name>
    
  • 相关阅读:
    BZOJ 1996: [Hnoi2010]chorus 合唱队
    BZOJ 2431: [HAOI2009]逆序对数列
    BZOJ1013: [JSOI2008]球形空间产生器sphere
    BZOJ 4196: [Noi2015]软件包管理器
    BZOJ 3670: [Noi2014]动物园
    NOIP 2017 提高组 day1t2 时间复杂度
    loj #6278. 数列分块入门 2
    CF285 E Positions in Permutations——“恰好->大于”的容斥和允许“随意放”的dp
    洛谷 1969 积木大赛——水题
    洛谷 1965 转圈游戏——水题
  • 原文地址:https://www.cnblogs.com/anliven/p/6354621.html
Copyright © 2020-2023  润新知