运行以下命令:
git init
touch README
git add README
git commit -m "Initial Commit"
git branch b01_02_03
git checkout b01_02_03
echo "Data 1" >> f1 && git add f1 && git commit -m "Add 01"
echo "Data 2" >> f2 && git add f2 && git commit -m "Add 02"
echo "Data 3" >> f3 && git add f3 && git commit -m "Add 03"
git checkout master
git branch b04_05
git checkout b04_05
echo "Data 4" >> f4 && git add f4 && git commit -m "Add 04"
echo "Data 5" >> f5 && git add f5 && git commit -m "Add 05"
git checkout master
git merge --ff-only b01_02_03
git checkout b04_05
形成以下测试树:
* 8294414 (HEAD, b04_05) add 05
* 19f920f add 04
| * 3a2ca64 (master, b01_02_03) add 03
| * 49d1aca add 02
| * c8f6d30 add 01
|/
* 7f0ca8e initial commit
我在跑步
git rebase master
并获取以下输出。
First, rewinding head to replay your work on top of it...
Applying: add 04
/opt/swt/install/git-1.7.12.3/libexec/git-core/git-am: line 115: /home9/tclarke/git-puzzles-1/.git/rebase-apply/next: cannot overwrite existing file
/opt/swt/install/git-1.7.12.3/libexec/git-core/git-am: line 665: 1: cannot overwrite existing file
/opt/swt/install/git-1.7.12.3/libexec/git-core/git-am: line 666: 1: cannot overwrite existing file
/opt/swt/install/git-1.7.12.3/libexec/git-core/git-am: line 712: 1: cannot overwrite existing file
Applying: add 04
/opt/swt/install/git-1.7.12.3/libexec/git-core/git-am: line 115: /home9/tclarke/git-puzzles-1/.git/rebase-apply/next: cannot overwrite existing file
结果是:
* c88b1f0 (HEAD, b04_05) add 04
* 761c779 add 04
* 3a2ca64 (master, b01_02_03) add 03
* 49d1aca add 02
* c8f6d30 add 01
* 7f0ca8e initial commit
成功变基,但日志被搞砸了,日志"add 05"变得与其前身相同。这可以在不同文件空间的不同计算机上,在我创建的新 git 存储库上重复。我的邻居在一棵相同的树上没有同样的问题。
关于如何解决这个问题的任何建议?
由于某种原因,某些存储库元文件的权限可能是错误的。
首先,尝试在本地存储库的主路径(/home9/tclarke/git-puzzles-1
)中运行chmod -R u+rw .git
,然后查看变基是否有效。(即使有,也要执行下一步)。
接下来,确保远程存储库已初始化为共享。在存储库的远程位置(为此需要 shell 访问权限),查看config
文件,以及在"[core]
"部分下是否有以下行:
sharedrepository = 1
如果缺少,请添加它,然后运行chmod -R g+w /path/to/repo
(并在[receive]
下也添加denyNonFastforwards = true
)。
最后,确保没有其他进程锁定本地存储库的元文件(想不出发生这种情况的原因,但仍然如此)。运行lsof | grep -F /home9/tclarke/git-puzzles-1/.git
,看看你是否想出了什么。