[英]Remove directory in hierarchy while preserving status in git
I have a repository like 我有一个像
/file1
/file2
/dir_a/file3
/dir_a/file4
...
how can I remove dir_a
and move all its content one directory up (in this case to /
) while keeping the status of all files (untracked, changed but not staged), which may be contained in /
but also in dir_a
? 我如何删除dir_a
并将其所有内容上移一个目录(在本例中为/
),同时保持所有文件的状态(未跟踪,已更改但未上演),这些文件可能包含在/
,也可能包含在dir_a
?
git-mv
should be able to handle this. git-mv
应该可以处理这个问题。 Use git mv -k dir_a/* .
使用git mv -k dir_a/* .
, and the staged/unstaged status will be preserved. ,则已分阶段/未分阶段状态将被保留。 This will not move untracked files, so use mv dir_a/* .
这不会移动未跟踪的文件,因此请使用mv dir_a/* .
afterwards. 然后。
# shelving unstaged stuff
git stash
# moving content from /dir_a to /
# that should suffice as git doesn't track directories but only files
git status -uno -s | grep "src_dir" | awk '{print "-n " $2 " dest_dir"}' | xargs -n3 git mv -f
# than move what remains in source dir manually:
mv src_dir/* dest_dir
# resurrect unstaged changes
git stash pop
Second line could be better but it worked for me. 第二行可能更好,但是对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.