Skip to content

git相关

  1. clone远程仓库
    git clone -b 分支名 <版本库的网址> <本地目录名>

  2. 撤销上1次的提交内容(commit)
    git reset --soft HEAD^  HEAD^的意思是上一个版本,也可以写成HEAD~1

  3. 撤销某文件的修改
    git checkout -- xx/xx

  4. 取消Git默认配置替换回车换行成统一的CRLF
    git config --global core.autocrlf false

  5. 忽略某些修改的文件,使其不提交
    git update-index --assume-unchanged xx
    恢复忽略
    git update-index --no-assume-unchanged xx
    若想要使整个文件夹都被忽略,可cd到文件夹目录
    git update-index -assume-unchanged $(git ls-files|tr 'n'”)

  6. 强制合并非关联的分支
    git merge upstream/v6 --allow-unrelated-histories
    git remote set-url origin xxx更改仓库地址
    git branch --set-upstream-to=origin/<branch>

  7. 更改git地址
    git remote set-url origin xx

smartgit rebase合并,解决冲突时,theirs是本地更改的内容

修改已提交记录的作者信息

sh
# 修改最近1条记录
git commit --amend --author="{username} <{email}>" --no-edit

# 批量修改所有符合条件的记录
git filter-branch --commit-filter '
    if [ "$GIT_AUTHOR_EMAIL" = "[email protected]" ];
    then
            GIT_AUTHOR_NAME="wang1xiang";
            GIT_AUTHOR_EMAIL="[email protected]";
            git commit-tree "$@";
    else
            git commit-tree "$@";
    fi' HEAD

# 如果执行时提示A previous backup already exists in refs/original/,说明已经执行过一次,使用以下命令解决
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD

# 如果已提交到远程,别忘了强制推送
git push -f