Git
Push when using two-factor authenticationg
啟用二階段驗證時,會無法push到server上
解決方法:
git config –global credential.helper store
Settings => Personal access tokens
Generate new token => token的範圍選repo就夠了 => click Generate Token
再次輸入:git push,輸入帳號,再密碼的地方輸入token就行了
備註 訊息會存在
~/.git-credentials
Generating a new SSH key
Open Git Bash.
Paste the text below, substituting in your GitHub email address.
This creates a new ssh key, using the provided email as a label.
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".
Adding your SSH key to the ssh-agent
Start the ssh-agent in the background.
If you're using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config
file to automatically load keys into the ssh-agent and store passphrases in your keychain.
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
ssh-add -K ~/.ssh/id_rsa
Note: The -K option is Apple's standard version of ssh-add, which stores the passphrase in your keychain for you when you add an ssh key to the ssh-agent.
救回 Commit
誤 reset 時,使用 reflog
觀看 git 的歷程
指定 Commit 即可救回
對底下的所有資料夾執行 git 指令
使用方法
複製整個資料夾到另外一個磁碟出現檔案已被修改
可能是因為檔案權限被異動 like 755=rwxr-xr-x
to 644=rw-r--r--
Suggests setting core.filemode to false.
移除本地已合併的分支
First, list all branches that were merged in remote.
You might see few branches you don't want to remove. we can add few arguments to skip important branches that we don't want to delete like master or a develop. The following command will skip master branch and anything that has dev in it.
If you want to skip, you can add it to the egrep command like the following. The branch skip_branch_name will not be deleted.
To delete all local branches that are already merged into the currently checked out branch:
You can see that master and dev are excluded in case they are an ancestor.
You can delete a merged local branch with:
If it's not merged, use:
To delete it from the remote use:
Once you delete the branch from the remote, you can prune to get rid of remote tracking branches with:
or prune individual remote tracking branches, as the other answer suggests, with:
設定 git ignore 命令並自動下載所需的 .gitignore 範本
Web API
該網站其實主要也只有兩個端點可用:
列出所有範本清單
取得特定範本內容
例如你要取得 VisualStudio 範本的內容,就可以直接呼叫
如果你想取得 dart 與 flutter 的範本,就可以直接呼叫
shell
請注意:官網提供的命令是以「單引號」包含字串,但這個設定並不適用於 Windows 的命令提示字元,建議改用「雙引號」,就可以同時適用於 Windows/Linux/macOS 所有的 Shell 執行環境。不過還是要設定一下驚嘆號的跳脫字元才能執行!
bash
取得範本清單
git ignore list
下載 VisualStudio 範本
git ignore visualstudio > .gitignore
同時下載 VisualStudio 與 ASPNETCore 範本
git ignore visualstudio,aspnetcore > .gitignore
快速調整 Git 設定的小工具
npx @willh/git-setup
各系統設定
Unix (Mac/Linux)Windowsinput
true
各設定值的作用 Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf setting. If you’re on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code:
git config --global core.autocrlf true
If you’re on a Linux or macOS system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:
git config --global core.autocrlf input
This setup should leave you with CRLF endings in Windows checkouts, but LF endings on macOS and Linux systems and in the repository.
If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false:
git config --global core.autocrlf false
Last updated