Cập nhật 2017:
Mới nhất Git 2.14/2.15 (Q4 2017) tài liệu lỗi
Xem commit c514167 (15 tháng 9 năm 2017) bởi Heiko Voigt (hvoigt
).
(Merged bởi Junio C Hamano -- gitster
-- trong commit 450b908, 25 Sep 2017)
Khi sử dụng git-mv
với một submodule nó sẽ phát hiện và cập nhật các đường dẫn cho các cấu hình của nó (.gitmodules
, worktree và gitfile).
Tính năng này không hoạt động đối với các mô-đun phụ đệ quy, trong đó người dùng đổi tên gốc là mô-đun con.
Original câu trả lời 2015
tôi chỉ thử nghiệm nó với git 2.6.0 (trên Windows), và các môđun con di chuyển với các môđun con lồng nhau của riêng mình dường như có vấn đề:
C:\Users\vonc\prog\git\tests\submove>git clone --recursive a a1
Cloning into 'a1'...
done.
Submodule '2015/b' (C:/Users/vonc/prog/git/tests/submove/b) registered for path '2015/b'
Submodule 'c' (C:/Users/vonc/prog/git/tests/submove/c) registered for path 'c'
Cloning into '2015/b'...
done.
Submodule path '2015/b': checked out 'dc18955ec7b9ad0c04245968e2474646e4d593b2'
Cloning into 'c'...
done.
Submodule path 'c': checked out 'fb4722eaca17ac171b7a2c8c5a1ac1e697f0ee85'
Submodule 'd' (C:/Users/vonc/prog/git/tests/submove/d) registered for path 'd'
Cloning into 'd'...
done.
Submodule path 'c/d': checked out '73cd7b8ff82519720b2fcca18df5ed00dd618b71'
tôi có:
a1
c
d
2015
b
Nếu tôi cố gắng và di chuyển submodule c
trong 2015 thư mục con:
C:\Users\vonc\prog\git\tests\submove\a1>git mv c 2015/c
C:\Users\vonc\prog\git\tests\submove\a1>git status
fatal: Not a git repository: d/../../.git/modules/c/modules/d
fatal: 'git status --porcelain' failed in submodule 2015/c
tôi thấy rằng tôi cần phải sửa đổi 2 điều trong module lồng nhau d
:
1/sửa đổi bằng tay .git/modules/c/modules/d/config
để tiêm con đường đúng đắn:
git config -f .git/modules/c/modules/d/config core.worktree ../../../../../2015/c/d
^^^^
2/sửa đổi d
worktree:
git config -f .git/modules/c/modules/d/config core.worktree ../../../../../2015/c/d
Từ đó, một git status
công trình, nhưng tôi thích (chắc chắn) để thêm một số git submodule sync --recursive
:
C:\Users\vonc\prog\git\tests\submove\a1>git submodule sync --recursive
Synchronizing submodule url for '2015/b'
Synchronizing submodule url for '2015/c'
Synchronizing submodule url for '2015/c/d'
git status
không hiển thị các kết quả mong đợi:
C:\Users\vonc\prog\git\tests\submove\a1>git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .gitmodules
renamed: c -> 2015/c
tôi thêm và cam kết rằng sự thay đổi:
C:\Users\vonc\prog\git\tests\submove\a1>git add .
C:\Users\vonc\prog\git\tests\submove\a1>git commit -m "move sub c in 2015/c"
[master 8289632] move sub c in 2015/c
2 files changed, 1 insertion(+), 1 deletion(-)
rename c => 2015/c (100%)
C:\Users\vonc\prog\git\tests\submove\a1>gl
* 8289632 - (HEAD -> master) move sub c in 2015/c (3 seconds ago) <VonC>
* 7ebb8e0 - (origin/master, origin/HEAD) a with sub c (38 minutes ago) <VonC>
bây giờ tôi sao chép repo đó để kiểm tra di chuyển đã thực sự đăng ký đúng:
C:\Users\vonc\prog\git\tests\submove>git clone --recursive a1 a2
Cloning into 'a2'...
done.
Submodule '2015/b' (C:/Users/vonc/prog/git/tests/submove/b) registered for path '2015/b'
Submodule 'c' (C:/Users/vonc/prog/git/tests/submove/c) registered for path '2015/c'
Cloning into '2015/b'...
done.
Submodule path '2015/b': checked out 'dc18955ec7b9ad0c04245968e2474646e4d593b2'
Cloning into '2015/c'...
done.
Submodule path '2015/c': checked out 'fb4722eaca17ac171b7a2c8c5a1ac1e697f0ee85'
Submodule 'd' (C:/Users/vonc/prog/git/tests/submove/d) registered for path 'd'
Cloning into 'd'...
done.
Submodule path '2015/c/d': checked out '73cd7b8ff82519720b2fcca18df5ed00dd618b71'
Như bạn có thể thấy, c
và c/d
nằm trong thư mục con mong muốn 2015/
:
C:\Users\vonc\prog\git\tests\submove>cd a2
C:\Users\vonc\prog\git\tests\submove\a2>dir 2015\c
Directory of C:\Users\vonc\prog\git\tests\submove\a2\2015\c
03/10/2015 18:10 <DIR> .
03/10/2015 18:10 <DIR> ..
03/10/2015 18:10 29 .git
03/10/2015 18:10 40 .gitmodules
03/10/2015 18:10 <DIR> d
2 File(s) 69 bytes
3 Dir(s) 23 656 910 848 bytes free
C:\Users\vonc\prog\git\tests\submove\a2>dir 2015\c\d
Directory of C:\Users\vonc\prog\git\tests\submove\a2\2015\c\d
03/10/2015 18:10 <DIR> .
03/10/2015 18:10 <DIR> ..
03/10/2015 18:10 42 .git
03/10/2015 18:10 3 d.txt
2 File(s) 45 bytes
2 Dir(s) 23 656 910 848 bytes free
Đó là âm thanh một awful nhiều như cách giải quyết hiện tại của tôi. Dù sao cũng cảm ơn bạn. – BartBog
@BartBog nghe có vẻ là giải pháp tối ưu và chính xác hơn. Nếu đây là một lỗi git, tôi không nghĩ rằng bạn sẽ nhận được một câu trả lời tốt hơn. – VonC
Nó thực sự là một chút ít bẩn vì nó liên quan đến việc không chỉnh sửa thủ công các tập tin cấu hình nhưng thay vì chỉnh sửa các worktrees với lệnh git. Tuy nhiên, nó là khá khó sử dụng. Bây giờ tôi đã cập nhật câu hỏi của mình cũng chứa luồng công việc mới nhất của tôi, bao gồm xóa môđun con d trước khi di chuyển (hoạt động khá tốt và không có sửa đổi phức tạp) – BartBog