html tool

显示标签为“git”的博文。显示所有博文
显示标签为“git”的博文。显示所有博文

2024年7月30日星期二

转:git本地缓存令牌

 https://blog.csdn.net/zhangzhanbin/article/details/122895656

git config credential.helper store

2023年9月20日星期三

转:修改git commit的提交内容

 参考:https://blog.csdn.net/zxc024000/article/details/108939049

修改最后一条提交内容:

git commit --amend

2022年10月24日星期一

转:切换git使用的key

 https://keysaim.github.io/post/git/2017-08-15-how-to-git-with-specific-ssh-key/

  • 配置ssh以使用新的key

    修改ssh的配置文件~/.ssh/config,加入如下配置:

    1
    2
    3
    4
    5
    Host github.com
    HostName github.com
    User git
    IdentityFile /Users/nbaoping/.ssh/id_rsa.github #切换为对应要的key就可以:)
    IdentitiesOnly yes

    下面逐行解释:

    • Host github.com

      用来指定该key的Host名字,此处必须使用本地repo的hostname github.com

    • Hostname github.com

      此处指定Host对应的具体域名,这里跟Host保持一致。(HostHostname可以不一致,但是Host必须跟repo的hostname保持一致,也就是git到时候会用自己repo的hostname来ssh配置文件里面找是不是有对应的Host,找到了就使用该配置,具体访问的域名会采用HostName

    • User git

      说明该配置的用户得是git

    • IdentityFile /Users/nbaoping/.ssh/id_rsa.github

      这行最为关键,指定了该使用哪个ssh key文件,这里的key文件一定指的是私钥文件。之前我们生成了新的私钥文件~/.ssh/id_rsa.github,由于博主使用的是MAC,~被翻译成/Users/nbaoping/了,如果是在一般的Linux环境下,改路径前缀该是/home/nbaoping/

    • IdentitiesOnly yes

      请配置为yes,具体意义可以参考讨论

2022年9月7日星期三

git 提交url转换

 来源:https://docs.github.com/cn/get-started/getting-started-with-git/managing-remote-repositories

  1. 列出现有远程仓库以获取要更改的远程仓库的名称。
    $ git remote -v
    > origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    > origin  git@github.com:USERNAME/REPOSITORY.git (push)
  2. 使用 git remote set-url 命令将远程 URL 从 SSH 更改为 HTTPS。
    $ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
  3. 验证远程 URL 是否已更改。
    $ git remote -v
    # Verify new remote URL
    > origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    > origin  https://github.com/USERNAME/REPOSITORY.git (push)

git 设置提交使用proxy

参考: https://cloud.tencent.com/developer/article/1563044

//socks5的代理 设置如下: git config http.proxy 'socks5://127.0.0.1:1080' git config https.proxy 'socks5://127.0.0.1:1080' 取消设置 git config --global --unset http.proxy git config --global --unset https.proxy

2022年3月24日星期四

转:Git HEAD detached from XXX (git HEAD 游离) 解决办法

 https://cloud.tencent.com/developer/article/1014809

【popexizhi:

detached的是 git用来解决merge的方式,也是处理时空交错的尝试吧:)

什么是 HEAD

Git 中的 HEAD 可以理解为一个指针,我们可以在命令行中输入 cat .git/HEAD 查看当前 HEAD 指向哪儿,一般它指向当前工作目录所在分支的最新提交。


当使用 git checkout < branch_name> 切换分支时,HEAD 会移动到指定分支。


但是如果使用的是 git checkout < commit id>,即切换到指定的某一次提交,HEAD 就会处于 detached 状态(游离状态)。


HEAD 游离状态的利与弊

HEAD 处于游离状态时,我们可以很方便地在历史版本之间互相切换,比如需要回到某次提交,直接 checkout 对应的 commit id 或者 tag 名即可。

它的弊端就是:在这个基础上的提交会新开一个匿名分支!


也就是说我们的提交是无法可见保存的,一旦切到别的分支,游离状态以后的提交就不可追溯了。


解决办法就是新建一个分支保存游离状态后的提交:


具体解决操作

  1. git branch -v 查看当前领先多少

    • 4449a91 指向的是 dev1 的最后一次提交
  2. 新建一个 temp 分支,把当前提交的代码放到整个分支

  3. checkout 出要回到的那个分支,这里是 dev1

  4. 然后 merge 刚才创建的临时分支,把那些代码拿回来

  5. git status 查看下合并结果,有冲突就解决

  6. 合并 OK 后就提交到远端

  7. 删除刚才创建的临时分支

  8. 查看 Log,当前 HEAD 指向本地 dev1 ,和远端 dev1 一致,OK 了!

Thanks

https://marklodato.github.io/visual-git-guide/index-zh-cn.html#detached https://git-scm.com/docs/git-checkout#_detached_head

2021年7月1日星期四

git remote 详细地址

 https://blog.csdn.net/u012672646/article/details/56831227

git remote -v

2020年12月14日星期一

转:git强制本地切换到远端分支

 https://blog.csdn.net/zoulonglong/article/details/79562922

有时候同一个分支,远程的和本地的都被修改的面目全非了,如果想要把本地的替换成远程的,用下面的命令


git fetch --all 
git reset --hard origin/master (这里master要修改为对应的分支名)
git pull【popezhi:git fetch 与git pull的区别是https://blog.csdn.net/riddle1981/article/details/74938111

git fetch和git pull都可以将远端仓库更新至本地那么他们之间有何区别?想要弄清楚这个问题有有几个概念不得不提。

FETCH_HEAD: 是一个版本链接,记录在本地的一个文件中,指向着目前已经从远程仓库取下来的分支的末端版本。
commit-id:在每次本地工作完成后,都会做一个git commit 操作来保存当前工作到本地的repo, 此时会产生一个commit-id,这是一个能唯一标识一个版本的序列号。 在使用git push后,这个序列号还会同步到远程仓库。

有了以上的概念再来说说git fetch
git fetch:这将更新git remote 中所有的远程仓库所包含分支的最新commit-id, 将其记录到.git/FETCH_HEAD文件中

2020年10月23日星期五

转:git diff 不同版本的一个文件的变动

 https://blog.csdn.net/zhezhebie/article/details/78496693

git diff 不同版本的一个文件的变动


查看任意两个版本之间的改动: 

git diff 版本号码1 版本号码2   filename

eg:

git diff f6cc57a7cb74714492819fc251341fc8a984eb17 b5fdc7e7aef15019e5fd25df1f819f58ca8cfc54  check_replay_res

2019年5月8日星期三

转: 如何从其他分支merge个别文件或文件夹


问题:

在dev  branch ,想使用dev7 branch 的tool 目录全部最新内容

解决方式:

1. dev branch 提交修改,切换到临时的 dev_tmp branch
2. git checkout dev7 tool (git checkout <branch>  <file/dir_ph>)
3. git commit -a -m "tool for new"  # 将2中的全部修改都提交了,使用最新的
4. 切换回dev branch ,git merge dev_tmp #将临时分支的全部提交merge回当前分支即可


参考:

https://juejin.im/post/5adff0d0f265da0b7f4434dc

2019年2月18日星期一

git commit 内容修改


https://segmentfault.com/q/1010000000761908
如果还没有push到服务器,只是本地进行了commit,并且没有进行新的commit,只需要git commit --amend;[popexizhi:只测试了这个 :),pass]
如果进行了新的commit,只需要git reset --soft xxx (xxx有问题那次提交的commit id),然后在进行git commit就行,不过所有后面的提交都成为了一次提交;如果想保持每次提交独立的话,使用
git checkout -b tmp ^xxx
git cherry-pick xxx
git commit --amend
git cherry-pick <依次后面的提交id>

2019年1月3日星期四

git 增加远程仓库


https://segmentfault.com/a/1190000011294144

方法一: 使用 git remote add 命令

1.1# 如下命令查看远程仓库的情况,可以看到只有一个叫 github 的远程仓库。
git remote
github

git remote -v
github  https://github.com/zxbetter/test.git (fetch)
github  https://github.com/zxbetter/test.git (push)
1.2# 使用如下命令再添加一个远程仓库(这里以码云为例)
[popexizhi:  git remote add ${name} ${url} 很好用,这个之后git push ${name} ${branch} 就ok了]
git remote add oschina https://git.oschina.net/zxbetter/test.git
1.3# 再次查看远程仓库的情况,可以看到已经有两个远程仓库了。然后再使用相应的命令 push 到对应的仓库就行了。这种方法的缺点是每次要 push 两次。
git remote
github
oschina

git remote -v
github  https://github.com/zxbetter/test.git (fetch)
github  https://github.com/zxbetter/test.git (push)
oschina https://git.oschina.net/zxbetter/test.git (fetch)
oschina https://git.oschina.net/zxbetter/test.git (push)

2018年10月9日星期二

github delete 指定的commit



https://tecadmin.net/delete-commit-history-in-github/

Delete Commit History in Git Repository

Follow the below steps to complete this task.
Warning: This will remove your old commit history completely, You can’t recover it again.
  • Create Orphan Branch – Create a new orphan branch in git repository. The newly created branch will not show in ‘git branch’ command.
    $ git checkout --orphan temp_branch
    
  • Add Files to Branch – Now add all files to newly created branch and commit them using following commands.
    $ git add -A
    $ git commit -am "the first commit"
    
  • Delete master Branch – Now you can delete the master branch from your git repository.
    $ git branch -D master
    
  • Rename Current Branch – After deleting the master branch, let’s rename newly created branch name to master.
    $ git branch -m master
    
  • Push Changes – You have completed the changes to your local git repository. Finally, push your changes to remote (Github) repository forcefully.
    $ git push -f origin master

2018年9月10日星期一

git clone 指定分支


http://www.cnblogs.com/nylcy/p/6569284.html

git clone -b 分支名仓库地址
  使用Git下载v.2.8.1分支代码,使用命令:git clone -b v2.8.1 https://git.oschina.net/oschina/android-app.git

2018年5月7日星期一

gitignore 正则使用


https://www.jianshu.com/p/13612fb4b224

.gitignore 文件格式规范如下:
  • 所有空行或#开头的行都会被忽略;
  • 可以使用标准的 glob 模式匹配;
  • 文件或目录前加 / 表示仓库根目录的对应文件;
  • 匹配模式最后跟反斜杠 / 说明要忽略的是目录;
  • 要特殊不忽略某个文件或目录,可以在模式前加上取反 !
其中 glob 模式是指 shell 所使用的简化了的正则表达式。
  • 星号 * 匹配零个或多个任意字符;
  • [abc]匹配任何一个列在方括号中的字符(这个例子要么匹配一个 a,要么匹配一个 b,要么匹配一个 c);- - 问号 ? 只匹配一个任意字符;
  • 如果在方括号中使用短划线分隔两个字符,表示所有在这两个字符范围内的都可以匹配(比如 [0-9] 表示匹配所有 0 到 9 的数字)。

2018年2月24日星期六

git tag push



https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE


分享标签

默认情况下,git push 并不会把标签传送到远端服务器上,只有通过显式命令才能分享标签到远端仓库。其命令格式如同推送分支,运行 git push origin [tagname] 即可:
$ git push origin v1.5
Counting objects: 50, done.
Compressing objects: 100% (38/38), done.
Writing objects: 100% (44/44), 4.56 KiB, done.
Total 44 (delta 18), reused 8 (delta 1)
To git@github.com:schacon/simplegit.git
* [new tag]         v1.5 -> v1.5

2018年1月26日星期五

git commit 修改



https://segmentfault.com/q/1010000000761908

git commit --amend 可以对上一次的提交做修改

git reset HEAD^应该也可以,但还没有测试(https://git-scm.com/book/zh/v1/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2

2017年12月18日星期一

git 修复 “”fatal: your current branch appears to be broken“”

https://stackoverflow.com/questions/33012869/broken-branch-in-git-fatal-your-current-branch-appears-to-be-broken


I meet similar issue on Windows 7. In my case,the current branch file (refer by ./git/HEAD) under \.git\refs\heads was broken.
I found the hash code of broken current branch on .git\logs\refs\heads with same branch name.
And I fixed the issue by opening that file (.git\logs\refs\heads\xxx) via notepad and copy the 4th number (the hash code) to (.git\refs\heads\xxx)

The files in .git\refs\heads directory are your branches. Check those files. They should contain only a single commit objects SHA-1 hash. This hash is your latest commits SHA-1 key and your HEAD at the same time.
Copy the SHA-1 key and type
$ git cat-file -t 5917fefd485f655ab369d4e9eeda3c157c03f514
commit

$ git cat-file -p 5917fefd485f655ab369d4e9eeda3c157c03f514
tree b75cab3c54b780075b312be3e878b389a2baf904
parent 8235189aa22169295243d295fb1cc2ff2f8f7cd5
author Ilker Cat  1495136738 +0200
committer Ilker Cat  1495136738 +0200
【popexizhi: 查了一下,自己也是相同的问题,重新拷贝一下对应的文件就ok了】

2017年9月14日星期四

备份git仓库

参考: https://gxnotes.com/article/71372.html


最佳解决方案

创建镜像:
git clone --mirror git://github.com/user/project.git
更新:
cd project.git
git remote update
要更新而不更改当前目录:
git --git-dir project.git remote update

2017年6月14日星期三

pipeline script中指定git 的branch clone


参考:https://stackoverflow.com/questions/38461705/checkout-jenkins-pipeline-git-scm-with-credentials

You can use the following in a pipeline:
git branch: 'master', credentialsId: '12345-1234-4696-af25-123455', url: 'ssh://git@bitbucket.org:company/repo.git'