Configure Git to use a proxy

Configure Git to use a proxy

为git配置socks5代理

git config --global https.proxy 'socks5://127.0.0.1:7890'

为git配置http代理

git config --global http.proxy http://@127.0.0.1:7890

展示已配置的代理:

git config --global --get-regexp http.*

参考教程
https://gist.github.com/evantoli/f8c23a37eb3558ab8765

In Brief

You may need to configure a proxy server if you’re having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port 

Or for a specific domain, something like:

git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
git config --global http.https://domain.com.sslVerify false 

Setting http.<url>.sslVerify to false may help you quickly get going if your workplace employs man-in-the-middle HTTPS proxying. Longer term, you could get the root CA that they are applying to the certificate chain and specify it with either http.sslCAInfo or http.sslCAPath.

See also the git-config documentation, especially the following sections if you’re having HTTPS/SSL issues

  • http.sslVerify
  • http.sslCAInfo
  • http.sslCAPath
  • http.sslCert
  • http.sslKey
  • http.sslCertPasswordProtected

In Detail

Configure the proxy

You can configure these globally in your user ~/.gitconfig file using the --global switch, or local to a repository in its .git/config file.

Setting a global proxy

Configure a global proxy if all access to all repos require this proxy

git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port 

URL specific proxy

If you wish to specify that a proxy should be used for just some URLs that specify the URL as a git config subsection using http.<url>.key notation:

git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port 

Which will result in the following in the ~/.gitconfig file:

[http]
[http "https://domain.com"]
    proxy = http://proxyUsername:proxyPassword@proxy.server.com:port 

Handle subsequent SSL protocol errors

If you’re still having trouble cloning or fetching and are now getting an unable to access 'https://...': Unknown SSL protocol error in connection to ...:443 then you may decide to switch off SSL verification for the single operation by using the -c http.sslVerify=false option

git -c http.sslVerify=false clone https://domain.com/path/to/git 

Once cloned, you may decide set this for just this cloned repository’s .git/config by doing. Notice the absence of the --global

git config http.sslVerify false 

If you choose to make it global then limit it to a URL using the http.<url>.sslVerify notation:

git config --global http.https://domain.com.sslVerify false 

Which will result in the following in the ~/.gitconfig file:

[http]
[http "https://domain.com"]
    proxy = http://proxyUsername:proxyPassword@proxy.server.com:port
    sslVerify = false 

Show current configuration

To show the current configuration of all http sections

git config --global --get-regexp http.* 

If you are in a locally cloned repository folder then you drop the --global and see all current config:

git config --get-regexp http.* 

Unset a proxy or SSL verification

Use the --unset flag to remove configuration being specific about the property – for example whether it was http.proxy or http.<url>.proxy. Consider using any of the following:

git config --global --unset http.proxy
git config --global --unset http.https://domain.com.proxy

git config --global --unset http.sslVerify
git config --global --unset http.https://domain.com.sslVerify 

微信开发者工具 版本管理 Azure Repo

通过ssh连接

生成ssh密钥
Windows Platform:
win+r键调出“运行”
输入cmd调出命令行
48510d187dc59f447bc4576b16cbdc40.png
输入
ssh-keygen -t rsa -C "xiaonan.pan"
-t rsa 表示采用 rsa 算法
-C “xiaonan.pan” 表示注释
93734751351e9e13ff5a9db7e727f0fb.png
键入 密钥保存的路径(一般照抄即可)

在给定的文件夹C:\Users\xiaon.ssh下,我们看到
3188872e89a0089a9e20ddb437a3db8b.png
id_rsa.pub即为公钥内容
选择记事本打开之
复制其中所有的内容,填写到GitHub的Key中
6e9553c6216f84d144054c9df2d1054a.png
a4622b799add66b0752bb413dcc9d20b.png
单击Add SSH key

Ubuntu Platform:
在终端输入
ssh-keygen -t rsa -C "xiaonan.pan"
后续步骤如上。

.ssh保存在 ~/.ssh/下
65f9496157f9c72ff0fe04d1a9e44871.png
利用
vim id_rsa.pub 
打开复制公钥,上传
在使用 git 命令行时注意使用SSH连接:
git clone git@ssh.dev.azure.com:v3/CPT202-GroupA-8/Maplus/Maplus

id_rsa 即为 rsa私钥,须保密保存
id_rsa 即为 rsa公钥,上传到Azure SSH key 管理页面

cd38127dc8ece3f586c3661d26454726.png

d742570eb34beadbc1a7d23a695f2eca.png

右下角确认add

随后配置微信开发者工具的版本管理
3faa4792f246fac391c044660e27dea5.png
设置

网络和认证改为
b208d48255ed44e6210876e95ef5871a.png
密码口令是刚刚 ssh生产中 passphase 的内容,此处我并没有设置passphase,故留空。

c7172f79cbb2e37242715dd38a7bbb9c.png
配置远程代码仓库

754df68baa544e476739a2aca73b0d43.png
URL填入SSH地址
16416134d217416dec23007b84a0d82d.png
804c0715c6d2f7922fa436fbd89e5fa7.png

配置完成。

Using Git

Intro

The git directory acts as a database for all the changes tracked in Git and the working tree acts as a sandbox where we can edit the current version of the files

Staging Area(index)

A  file maintained by Git that contains all of the information about what files and changes are going to go into your next commit

Any Git project will consist of 3 sections: Git directory, working tree, Staging area

After modifying a file, we need to stage those changes and then commit them afterwards

chmod +x all_check.py //makes the scripts excutable

A commit message is required, or the commit will be aborted

which command would we use to view pending changes?
git status 

to generate a patch to fix the current bug
diff fix_permission.py fix_permissions_modified.py > fix_permission.patch

apply the patch to the file:
patch fix_names.conf < fix_names.patch 

the wdiff commandhighlights the words that changed in a file instead of working by line

A commit is a collection of edits which has been submitted to the version control system for safe keeping

Within a VCS, project files are organized in centralized locations called repositories where they can be called upon later

Git 常见命令

git add will add a file to the staging area and mark it for tracking

git log will give us information about the author of each commit, its timestamp, and each commit message

git config -l is used to check the current user configuration

git status is used to retrieve information about changes waiting to be committed

user@ubuntu: ~$ git config --global user.email "me@example.com"
user@ubuntu: ~$ git config --global user.name "My name"

Workflow

init git:

user@ubuntu: ~$ mkdir checks
user@ubuntu: ~$ cd checks
user@ubuntu: ~/checks$ git init
Initialized empty Git repository in /home/user/checks/.git/

The area outside the git directory is the working tree. The working tree is the current version of your project.

add git

-m to pass the commit message
user@ubuntu: ~/checks$ git commit -m 'Add periods to the end of sentences.'

anatomy of a  Commit Message

  • short summary
  • detailed explaation
  • more infomation related to the message

git log :
4a214c047c5e1c49c6c1edc7b0703ee8.png
git log -p 

git commit -a 
A shortcut to stage any changes to tracked files and commit them in one step
git commit -a dosen’t work on new files

Can only write short message

user@ubuntu:~/scripts$ git commit -a -m "Call check_reboot from main, exit with 1 on error"

for truely small changes

Git uses the HEAD alias to represent the currently checked-out snapshot of your project.

This lets you know what the contents of your working directory should be.

user@ubuntu:~/scripts$ git add -p

#when using -p flag, git will show us the change being added and ask us if we want to stage it or not

user@ubuntu:~/scripts$ git diff #only unstaged changes by default

user@ubuntu:~/scripts$ git diff -staged #to see the changes that are staged but not committed

we can see the actual stage changes before we call git commit

You can remove files from your repository with the git rm command, which will stop the file from being tracked by git and remove it from the git directory

git checkout
followed by the name of the file you want to revert.

git reset

We’ve added something to the staging area that we didn’t actually want to commit, we can unstage our changes by using git reset.

git add
end up adding any change done in the working tree to the staing area

--amend
git commit --amend
overwirte the previous commit

Avoid amending commits that have already been made public

With git revert, a new commit is created with inverse changes. This cancels previous changes instead of making it as though the original commit never happened.

You can verify the data you get back out is the exact same data you put in

git show

help us easily view the log message and diff output the last commit if we don’t know the commit ID

8d7f473673c37118f4219256950412bc.png

git show hashcommitid
ca21b42d229ac74ac7320a1603bb76d4.png

git revert hashcommitid
user@ubuntu:~/scripts$ git revert 30e70