https://blog.csdn.net/zhangzhanbin/article/details/122895656
git config credential.helper store
https://keysaim.github.io/post/git/2017-08-15-how-to-git-with-specific-ssh-key/
配置ssh以使用新的key
修改ssh的配置文件~/.ssh/config,加入如下配置:
| |
下面逐行解释:
Host github.com
用来指定该key的Host名字,此处必须使用本地repo的hostname github.com。
Hostname github.com
此处指定Host对应的具体域名,这里跟Host保持一致。(Host跟Hostname可以不一致,但是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,具体意义可以参考讨论。
来源:https://docs.github.com/cn/get-started/getting-started-with-git/managing-remote-repositories
$ git remote -v
> origin git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin git@github.com:USERNAME/REPOSITORY.git (push)git remote set-url 命令将远程 URL 从 SSH 更改为 HTTPS。$ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git$ git remote -v
# Verify new remote URL
> origin https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin https://github.com/USERNAME/REPOSITORY.git (push)https://cloud.tencent.com/developer/article/1014809
【popexizhi:
detached的是 git用来解决merge的方式,也是处理时空交错的尝试吧:)
】
Git 中的 HEAD 可以理解为一个指针,我们可以在命令行中输入 cat .git/HEAD 查看当前 HEAD 指向哪儿,一般它指向当前工作目录所在分支的最新提交。
当使用 git checkout < branch_name> 切换分支时,HEAD 会移动到指定分支。
但是如果使用的是 git checkout < commit id>,即切换到指定的某一次提交,HEAD 就会处于 detached 状态(游离状态)。
HEAD 处于游离状态时,我们可以很方便地在历史版本之间互相切换,比如需要回到某次提交,直接 checkout 对应的 commit id 或者 tag 名即可。
它的弊端就是:在这个基础上的提交会新开一个匿名分支!
也就是说我们的提交是无法可见保存的,一旦切到别的分支,游离状态以后的提交就不可追溯了。
解决办法就是新建一个分支保存游离状态后的提交:
dev1 的最后一次提交checkout 出要回到的那个分支,这里是 dev1 merge 刚才创建的临时分支,把那些代码拿回来 git status 查看下合并结果,有冲突就解决 https://marklodato.github.io/visual-git-guide/index-zh-cn.html#detached https://git-scm.com/docs/git-checkout#_detached_head
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/74938111git 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文件中
】
https://blog.csdn.net/zhezhebie/article/details/78496693
git diff 不同版本的一个文件的变动
查看任意两个版本之间的改动:
git diff 版本号码1 版本号码2 filename
eg:
git diff f6cc57a7cb74714492819fc251341fc8a984eb17 b5fdc7e7aef15019e5fd25df1f819f58ca8cfc54 check_replay_res
git commit --amend;[popexizhi:只测试了这个 :),pass]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>
git remote add 命令github 的远程仓库。git remote
github
git remote -v
github https://github.com/zxbetter/test.git (fetch)
github https://github.com/zxbetter/test.git (push)
git remote add oschina https://git.oschina.net/zxbetter/test.git
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)
$ git checkout --orphan temp_branch
$ git add -A $ git commit -am "the first commit"
$ git branch -D master
$ git branch -m master
$ git push -f origin master
.gitignore 文件格式规范如下:/ 表示仓库根目录的对应文件;/ 说明要忽略的是目录;! 。* 匹配零个或多个任意字符;[abc]匹配任何一个列在方括号中的字符(这个例子要么匹配一个 a,要么匹配一个 b,要么匹配一个 c);- - 问号 ? 只匹配一个任意字符;[0-9] 表示匹配所有 0 到 9 的数字)。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
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)
【popexizhi: 查了一下,自己也是相同的问题,重新拷贝一下对应的文件就ok了】
|
git branch: 'master', credentialsId: '12345-1234-4696-af25-123455', url: 'ssh://git@bitbucket.org:company/repo.git'