當進行 gir push 發生 “non-fast-forward” 錯誤時 (如下面這個範例)
root@ubuntu:/mnt/tdg_logs/blacklist/Git/master# git push -u 20140821 master
Enter passphrase for key '/root/.ssh/id_rsa':
To git@cowman.no-ip.org:udn/udn_php-domain_name_query.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@cowman.no-ip.org:udn/udn_php-domain_name_query.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
會有幾個可能性, 可以透過 git status
先查看是不是有需要手動 merge 的部分
假設有出現 Unmerged paths 的資訊就是需要手動處理一下
root@ubuntu:/mnt/tdg_logs/blacklist/Git/master# git status
# On branch master
# Unmerged paths:
# (use "git add/rm ..." as appropriate to mark resolution)
#
# both added: JobDaemon.php
# both added: ReadME
# both added: daily.sh
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# 20140801/
# 20140815.zip
# 20140821.zip
# JobDaemon.php.bak
no changes added to commit (use "git add" and/or "git commit -a")
這時候就要針對 JobDaemon.php、ReadME、daily.sh 進行編輯
在檔案中可以看到
<<<<<<<<<< HEAD
要新推上去的檔案內容
==========
原始branch的檔案內容
>>>>>>>>>>>
目前是先保留新推上去的檔案內容為主~將<<<、===、原始的內容、>>>刪除後重新 git add、git commit
後重新push即可
另外一個可能性是要進行 git pull 要推上去的remote 要推到的branch名稱
root@ubuntu:/mnt/tdg_logs/blacklist/Git# git pull 20140825 master
Enter passphrase for key '/root/.ssh/id_rsa':
warning: no common commits
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 18 (delta 7), reused 0 (delta 0)
Unpacking objects: 100% (18/18), done.
From cowman.no-ip.org:udn/udn_php-domain_name_query
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
root@ubuntu:/mnt/tdg_logs/blacklist/Git# git push 20140825 master
Enter passphrase for key '/root/.ssh/id_rsa':
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 305 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To git@cowman.no-ip.org:udn/udn_php-domain_name_query.git
07152a6..ccd7420 master -> master