顯示具有 Git 標籤的文章。 顯示所有文章
顯示具有 Git 標籤的文章。 顯示所有文章

107.10.27 [Git] 修改已經 push 的 commit 訊息

首先把當下的修改做 commit 或 stash
請隨時愛用 git log 和 git status 查看當前狀態
以下為真實例子,要修改的已經 push 而本地端又多兩個 commit

$ git log
commit 452143805e8720f1085a7d14585f07cd6be4cb95 (HEAD -> master)
Author: aben20807 
Date:   Sat Oct 27 19:39:39 2018 +0800

    Implement specialBits()
    
    Because 0xffca3fff has exactly 1 byte 0b00101000
    in the middle, use its complement 0b11010111 to
    shift left 14 bits and complemet it finally.

commit e36bee804ba0bd24a2f4b3658488ca3d5ad11e37
Author: aben20807 
Date:   Sat Oct 27 19:36:43 2018 +0800

    Ignore .swp files

commit 77883e77862f88fc91730ca9a2035fb1d6c5ddf3 (origin/master, origin/HEAD)
Author: aben20807 
Date:   Sat Oct 27 17:32:02 2018 +0800

    Fix shifting warnings from cppcheck
    
    Because cppcheck will complain when shifting signed 32-bit
    value by 31 bits, this commit change these variables that
    needs to shift 31 bits to become unsigned and add the
    integer-suffix 'u' to integer constants.
    For example:
    `x >> 31` becomes `(unsigned) x >> 31`
    `1 >> 31` becomes `1u >> 31`

commit c33896f8fb684227102284a7313228cb876bd716

我要修改 77883e77862f88fc91730ca9a2035fb1d6c5ddf3 的 commit 訊息

107.03.02 git push 免帳號密碼 | ssh key

基本上一個環境執行一次即可
但是步驟偏多,所以還是記錄個 OuO

<注意>請在自己熟悉的環境使用 ssh key,請勿在公共電腦使用

1. 檢查 ssh key
基本上都會顯示不存在,若已有,請先備份
$ cd ~/.ssh

107.01.25 git add another remote

因為我三上OS作業要用 git 版本控制
而課程自己有架設 GitLab
但是若要把這個 repository 原封不動的也 push 到 github 呢?

說原封不動是因為這樣可以保留所有的 commit
不然新增一個新的 repository ,clone 下來後把檔案複製進去再 push 就好
保留所有的 commit 是比較好的,可以讓你的 contributions 比較好看(x

其實方法很簡單
就是再新增一個遠端給它
<順帶一提> git init 後也可以透過這個方法 push 到遠端喔

首先到你的 GitHub 新增一個 repository
名字可以跟其他遠端、本地端專案資料夾不一樣喔
<注意> 下方的 README、.gitignore、license 都不能加
因為 push 上去前它會判斷 commit 的時間,如果遠端的比本地的還要新就不給 push

106.08.17 解決git無法add

錯誤訊息:
fatal: Unable to create '/home/user/pro/selfpro/learn_rust/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

106.07.18 vim相關作git管理

我原本是用頗笨的方法
新增一個 my_vim 的資料夾來當遠端
vim 相關的東西一有變動就複製然後覆蓋資料夾內的檔案
然後因為有大量檔案,所以每次都超久
有點煩=''=
就發現 symbolic links 這個東西
總之就是類似捷徑的東西,詳情可以來 wiki - Symbolic link 看看
結果會如下

106.03.13 git 資料夾重新命名

資料夾若自己改名字時,使用git add它並不會視作是改變
所以需要使用git mv來更改
語法:
git mv [old name] [new name]
但若是要修改開頭字母的大小寫它會說錯誤
就來記錄個(其實不難XDD)
p.s.改名之前先確定要改名專案使用的IDE可否允許外部改名喔(有點繞口令@@

原本長這樣















105.12.21 git 的 alias 設定

因為換了新電腦了
很多東西要重新設定
例如說這篇的,如果沒有這個就無法懶惰了OuO

step 1
在終端機打上:(由於我是新安裝 Cygwin,所以如果不是用這個或舊版本的可能不適用)
記得先回到 ~
vim .gitconfig

step 2
進入編輯模式
在下方加入懶人捷徑指令OuO
接著 :wq 離開
[alias]
        aa = add --all
        st = status
        graph = log --pretty=oneline --decorate --graph
        lg = log --color --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
就完成啦
截圖如下

^ Top