avatar

目錄
Git command 常用指令

Generate SSH key

bash
ssh-keygen -t rsa -b 4096 -C "yourname/email address"

After then, the ssh key files will be generated and saved at C:\Users\username/.ssh/id_rsa
Public key = file id_rsa.pub

ssh-keygen 命令依預設會在 ~/.ssh 目錄中產生 4096 位元的 SSH RSA 公開和私密金鑰檔案。 如果現有的 SSH 金鑰組存在於目前的位置,系統將會覆寫這些檔案。

Options Explanation
-t Type. 指定要生成的密鑰的類型,在此案例中採用 RSA 格式
-b Number of bits in generated key. 在此案例中為 4096 bits.
-C Comment. 附加至公開金鑰檔案結尾以便輕鬆識別的註解。 通常會以電子郵件地址作為註解,但您可以使用任何最適合您的基礎結構的項目。

Config

bash
git config --global user.name "your usesrname"
git config --global user.email "your email address"

New git repo

bash
git init   # 創建一個空的Git倉儲或是重新初始化已存在的倉儲
git remote add origin git@<the address>/<repo name>.git
git add . # 新增目前目錄下的所有檔案到暫存區
git commit -m "Initial commit"
git push -u origin master

New branch

bash
git init
git remote add origin git@<the address>/<repo name>.git
git checkout -b <branch_name> # create a new branch
git branch --show-current # check we are currently in which branch
git add .
git commit -m "Initial commit"
git push -u origin <branch_name>

clone branch

Code
git clone --branch <branch-name> <repository-url>

show the current branch

Code
git branch --show-current

Check git config user account

This command will display all your Git configurations, including your username, email address, and other settings.

Code
git config --list

To set a global configuration that applies to all repositories on your machine, use the –global flag with the git config command. For example, to set your global username and email, you can use the following commands:

Code
git config --global user.name "Your Global Username"
git config --global user.email "your-email@example.com"

To set a local configuration that applies only to a specific repository, navigate to the repository’s directory in the terminal. Then, use the git config command without the –global flag. For example, to set the username and email for a specific repository, you can use the following commands:

Code
git config user.name "Your Local Repository Username"
git config user.email "your-local-email@example.com"

VS Code Git Source Control - user

Set particular github user account as the VS code git control commit user

Code
code --help
git config --global core.editor "code --wait"
git config --global -e

The following files will pop up. Edit the user name and email.

Code
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[user]
name = <your-github-username>
email = <your-github-email>
[core]
autocrlf = false
editor = code --wait

Delete previous commit history

1.

Code
git rebase -i HEAD~1
  1. it will then enter to an editor. In line 1, change pick to drop. Then, ESC :wq to save and quit.
Code
git rebase --continue
git push --force origin <branchname>

By following these steps, you can delete a specific commit from the commit history of a GitHub repository.


References


如果您喜歡我的文章,歡迎幫我在下面按5下讚!感謝您的鼓勵和支持!

文章作者: ouoholly
文章鏈接: https://ouoholly.github.io/post/git-command-notes/
版權聲明: 本博客所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。歡迎「部份引用」與介紹(如要全文轉貼請先留言詢問),轉載引用請註明來源 ouoholly 的倉庫,謝謝!

評論