标签: Git

  • git文件过大 .git目录过大 解决办法 图文教程

    git文件过大 .git目录过大 解决办法 图文教程

    git在长久使用以后,体积会变得越来越臃肿。原来在于.git目录下的objects下有pack的文件,体积非常大,要解决这一问题,只需要使用一下几个命令就可以啦

    • 首先找到.git目录下体积比较大的问题,进行重建索引,代码
    git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch .git/objects/pack/xxxxx.pack' --prune-empty
    把xxxx.pack替换你实际需要删除的pack
    • 删除和重建的索引
     git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
    • 设置reflog过期
    git reflog expire --expire=now --all
    • 清理垃圾
    git gc --aggressive --prune=now
  • brew install 时出现 fatal: not in a git directory Error: Command failed with exit 128: git 解决办法 图文教程

    brew install 时出现 fatal: not in a git directory Error: Command failed with exit 128: git 解决办法 图文教程

    fatal: not in a git directory Error: Command failed with exit 128: git
    执行​​ brew install cmake​​ 遇到了下面的错误

    Already downloaded: /Users/kingcall/Library/Caches/Homebrew/downloads/b7ef8d6eb909e967d072212c62e71bfb8e94e6227ae2d3567bbabcc561fd9fff–cmake-3.21.4.bottle_manifest.json
    ==> Downloading https://ghcr.io/v2/homebrew/core/cmake/blobs/sha256:c86a0bb0e37c293e2d4475519d28f2784c430e871f74969a1a2afeb64b540a7d
    Already downloaded: /Users/kingcall/Library/Caches/Homebrew/downloads/1e8ca69a4444469a3f380baf4e514072d4d0f0b5d5ccd43b8ce3eb68081eff3d–cmake–3.21.4.arm64_monterey.bottle.tar.gz
    fatal: not in a git directory
    Error: Command failed with exit 128: git
    解决方法如下:

    执行brew -v 查看会有两个提示,提示用户设置 ​​homebrew-cask​​​ 和 ​​homebrew-core​​ 的文件路径为设置为safe.directory, 即使用如下命名:

    根据提示执行

    git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
    git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask


    之后再执行 ​​arch -arm64 brew install cocoapods​​ 即可

    如果遇到上面的错误则根据提示执行

    git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-services

    然后再次执行​​arch -arm64 brew install cocoapods​​ 即可成功。

    执行成功后我们再次执行我们的安装命令 ​​brew install cmake

  • git回滚和git分离头指针

    git回滚和git分离头指针

    查看提交记录 

    git log

    记录ID 回滚到某一提交记录  

    git reset –hard

    分离头指针(detached HEAD)#

    detached HEAD

    通常,我们工作在某一个分支上,比如 master 分支。这个时候 master 指针和 HEAD 指针是一起前进的,每做一次提交,这两个指针就会一起向前挪一步。但是在某种情况下(例如 checkout 了某个具体的 commit),master 指针 和 HEAD 指针这种「绑定」的状态就被打破了,变成了分离头指针状态。我那天遇到的情况是,master 和 HEAD 指针看上去指在同一个 commit 上,但其实已经处在分离头指针状态。当我在此时又做了一次新的提交时,HEAD 指针跑到 master 指针前面去了。如果我直接检出 master 分支,HEAD 指针就会回退一格到 master 指针的位置,而最新的那次提交就变成了孤立的提交,没有任何分支能追踪到它,刚才的活白干了。

    吃一堑长一智,下面是解决办法:

    # 强制将 master 分支指向当前头指针的位置
    git branch -f master HEAD
    # 检出 master 分支
    git checkout master
  • 使用 Composer 的时候提示输入Token (hidden):

    使用 Composer 的时候提示输入Token (hidden):

    出现了Could not fetch https://api.github.com/ 。。。please create a GitHub OAuth token to go over the API rate limit 。。。 to retrieve a token.  。。。 Token (hidden):

    进入 https://github.com/settings/tokens 点击 「Generate new token」 新建一个 Token,选择默认新建就行,然后就会得到一个 Token,然后输入这个值就 OK 了。

    help:1.生成Token 请选择 gist Create gists,这项,复制粘贴才能成功

       2.粘贴前最好确定没有输入其他东西(先按几下backspace比较保险),粘贴完了就按回车键就可以了,Token(hidden) 是不显示的。

    注意:一般出现填写token,可能都是因为频繁下载,申请token的号可能会被github屏蔽,最好用新号哦!

  • github上fork的项目,如何同步原作者更新的内容?

    github上fork的项目,如何同步原作者更新的内容?

    我在github上fork了一个项目,之后原作者又更新了内容,我想把原作者更新的内容同步到我fork的项目仓库中。在此记录一下同步步骤。

    打开fork的项目的主页,点击New pull request

    把上图中的base repository和head repository互换位置

    按照以上步骤操作之后,会出现下图的页面

    Create pull request

    Merge pull request
    找到自己项目仓库的Pull Request

    查看刚刚创建的Pull request,比较更改的内容,如果没问题就往下拉页面找到Merge pull request,点击按钮即可完成同步

  • git push 提交操作出现 fatal: Authentication failed for 错误 解决方案

    git push 提交操作出现 fatal: Authentication failed for 错误 解决方案

    场景描述

    通常我们在日常开发时一般使用记住git密码功能,但是如果密码输入错误了就不会再弹出输入密码框了。

    git add . ; git commit -m ‘laoji.org ‘ ; git push
    On branch master
    Your branch is ahead of ‘origin/master’ by 1 commit.
    (use “git push” to publish your local commits)
    nothing to commit, working tree clean
    remote: Coding 提示: Authentication failed.
    remote: 认证失败,请确认您输入了正确的账号密码。

    配置用户信息

    git config --global user.name [username]
    git config --global user.email [email]

    查询用户信息

    git config --list

    3、如果push遇到在输入密码是熟错后,就会报这个错误fatal: Authentication failed for

    解决办法( 请使用管理员运行

    git config --system --unset credential.helper

    之后你在push就会提示输入名称和密码

    如不使用管理员运行可能会出现如下错误:

    error: could not lock config file C:/Program Files/Git/mingw64/etc/gitconfig: Permission denied

  • Git如何设置多个远程仓库地址?

    Git如何设置多个远程仓库地址?

    老季已经明显感觉到记忆力衰退了,只好发文章记录一下。Git在我们程序日常开发中经常使用,而且我们前面也记录了一些技巧。

    不对老季对于Git的使用还是非常低级的,停留在可视化工具上。 产品一直是用国内的 Gitee (码云)托管(因为有免费的私有仓库), 自从 Github 免费了私有仓库,老季就将一些作品也弄了一份到 GitHub,所以本地就需要配置两个远程仓库链接地址。【WordPress 采集插件 WP-JPost

    设置方法很简单,先在GitHub创建了一个仓库,然后克隆回本地,就可以在本地仓库根目录看到一个隐藏的 .git 目录,进去目录后编辑 config 文件(可以用文本或者其他编辑器):

    按照图片说明操作即可。保存后git更新提交即可。

  • git代码管理:使用git push时错误:error: unable to rewind rpc post data – try increasing http.postBuffer error: RPC failed; curl 56 SSLRead() return error -36

    git代码管理:使用git push时错误:error: unable to rewind rpc post data – try increasing http.postBuffer error: RPC failed; curl 56 SSLRead() return error -36

    error: unable to rewind rpc post data – try increasing http.postBuffer error: RPC failed; curl 56 SSLRead() return error -36

    大概意思是http.postBuffer太小,需要设置更大的值,应该是我们项目中用到的第三方静态库有400多MB大小的单个.a文件。

    谷歌查了相关资料,在终端执行

    git config --global http.postBuffer 524288000

    命令,将http.postBuffer设置为500MB大小后,可以正常push操作了。

  • Git中从远程的分支获取最新的版本到本地

    Git中从远程的分支获取最新的版本到本地

    Git中从远程的分支获取最新的版本到本地有这样2个命令:

    1.git fetch:相当于是从远程获取最新版本到本地,不会自动merge

    git fetch origin master
    git log -p master..origin/master
    git merge origin/master

    以上命令的含义:
    首先从远程的origin的master主分支下载最新的版本到origin/master分支上
    然后比较本地的master分支和origin/master分支的差别
    最后进行合并

    上述过程其实可以用以下更清晰的方式来进行:

    git fetch origin master:tmp
    git diff tmp
    git merge tmp

    从远程获取最新的版本到本地的test分支上
    之后再进行比较合并

    2. git pull:相当于是从远程获取最新版本并merge到本地

    git pull origin master

    上述命令其实相当于git fetch 和 git merge
    在实际使用中,git fetch更安全一些
    因为在merge前,我们可以查看更新情况,然后再决定是否合并

  • Git 设置远程仓库 初始化push 图文教程

    Git 设置远程仓库 初始化push 图文教程

    Git – setting up a remote repository and doing an initial push

    There is a great deal of documentation and many posts on Git out there, so this is more of a note to self as I keep forgetting the steps needed to set up a remote repository and doing an initial “push”.

    这里记录一下push远程仓库所需要的步骤:

    So, firstly setup the remote repository:

    首先设置远程仓库:

    ssh git@example.com
    mkdir my_project.git
    cd my_project.git
    git init --bare
    git update-server-info # If planning to serve via HTTP
    exit

    On local machine:

    本地机器:

    cd my_project
    git init
    git add *
    git commit -m "My initial commit message"
    git remote add origin git@example.com:my_project.git
    git push -u origin master

    Done!

    完成!

    Team members can now clone and track the remote repository using the following:

    其他团队成员直接克隆远程仓库内容即可:

    git clone git@example.com:my_project.git
    cd my_project

    Bonus

    To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile (I have my current directory displayed in cyan):

    function git-branch-name {
      git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
    }
    function git-branch-prompt {
      local branch=`git-branch-name`
      if [ $branch ]; then printf " [%s]" $branch; fi
    }
    PS1="\u@\h \[\033[0;36m\]\W\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "
  • git 保存用户名与密码 图文教程

    git config --global credential.helper cache

    … which tells git to keep your password cached in memory for (by default) 15 minutes. You can?set a longer timeout?with:

    记住密码一个小时:

    git config --global credential.helper "cache --timeout=3600"

    Windows客户端保存密码:

    git config --global credential.helper winstore

    或者手动修改 .gitconfig文件:

    [credential]
        helper = winstore
    git config --global credential.helper store
  • git 修改代码并提交修改文件到远程服务器教程

    修改文件后,如何提交到git服务器,我们现在给出具体步骤:

    (1)首先需要add,比如.config是被修改的文件,则?git add .config

    (2)然后执行?git commit -m "这里写原因,比如:修改了网站 v.jiloc.com"

    (3)然后push到git服务器,git push

    (4)更新:git pull

    (5)查看log:git log

WeChat