在Linux根目录初始化Git仓库的影响

8
我正在运行安装在SD卡上的Ubuntu系统中的Beaglebone Black。我正在学习通过安装各种软件包(就像CERN的研究员通过以不同角度碰撞亚原子粒子并研究它们的轨迹来学习这些粒子一样)试错法编程该设备。因此,我能否在根目录初始化git仓库并忽略易变的目录如/sys和/proc?或者观察哪些系统目录足以成功跟踪整个操作系统的时间轴?还有其他类似的快照工具吗?除了git之外,哪种存储库系统最适合跟踪二进制文件?
--编辑--
在/中,哪些是非易失性且重要的目录(不像/tmp)?

1
你可以使用Git跟踪所有文件,正如你所注意到的,你很快就会想要忽略一些目录。然而,我认为CERN的人们正在采取他们的方法,因为他们确实没有任何替代方案。你有很多选择,并且可能考虑阅读一些文档来从两个方面(实践和理论)解决问题。 - mnagel
@mnagel 有时候这是最简单的方法 :) - Necktwi
嗯,你可以在Windows上没有管理员权限的情况下在“/”上运行“git init”... - 9pfs
3个回答

2
无论如何,我敢在 / 上启动了git仓库,因为它只是安装在8GB SD卡上的Beaglebone Black上的ARM Ubuntu,并且我们将ARM Ubuntu作为扇区到扇区SD卡映像获取,所以我们不能选择ZFS或BTRFS。 我可以在任何Linux机器上挂载SD卡并检出分支。
cd /
sudo git init
sudo vi .gitignore
/dev/
/lost+found/
/media/
/mnt/
/opt/
/proc/
/run/
/srv/
/sys/
/tmp/
/var/log/

sudo git add -A
sudo du -sh .git
297M    .git
git config --global user.name 'Your Name'
git config --global user.email you@somedomain.com
sudo git commit -m "initial update and network configured"
sudo du -sh .git
308M    .git

请提供我可以忽略的文件夹或文件。我会不断更新这个答案,列出忽略列表和我遇到的问题。
2013年7月18日21:59:00 IST 我的第一次检出让我有了糟糕的经历。当我尝试检出之前的提交时,它会抛出一些锁定失败的错误。犯了一个错误,没有记录输出。
然后我从BeagleBone上取下SD卡,并将其安装在我的Ubuntu桌面上。每个分区都给了2个挂载点/media/rootfs//media/boot/。我重新挂载了/media/boot//media/rootfs/boot/uboot,所以现在文件系统与在BeagleBone上启动的实时文件系统完全相同。
$ sudo cd /media/rootfs
$ sudo git log
commit 8bf5b7031bc1aee6392272da4eae2b808b46912f
Author: gowtham <gowtham@beaglebone>
Date:   Thu Jul 18 12:04:05 2013 +0000

    remotedevicecontroller with camcapture-compression option

commit 774765de36a0c3cc7280a29275c37928de982f6e
Author: gowtham <gowtham@beaglebone>
Date:   Thu Jul 18 06:19:48 2013 +0000

    before installing remotedevicecontroller with camcapture-compression

commit 19d5f3f66f29cbe925b8743c7248770d1f1d6ba4
Author: gowtham <gowtham@beaglebone>
Date:   Wed Jul 17 13:34:33 2013 +0000

    ffmpeg installed by remotedevicecontroller

commit 691c20afd7b166103dabc2561c72eb94c172e726
Author: gowtham <gowtham@beaglebone>
Date:   Wed Jul 17 14:44:17 2013 +0000

    initial update and network configured
$ sudo git stash
[sudo] password for gowtham: 
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
You do not have the initial commit yet

但是.git/存在于/media/rootfs/中。请在下方评论指出我所犯的错误。


2

你可以使用支持快照的文件系统,例如ZFSBTRFS,而不是使用git。这样更高效,并且使用起来对你来说是透明的。


我现在可以将我的文件系统从ext4更改为zfs吗? - Necktwi
据我所知,将现有的文件系统(如ext4)切换到ZFS(或BTRFS)并不是一件简单的事情,尤其是在运行中的系统上。解决方案可能是重新安装系统,或者仅在新分区上使用新的文件系统。 - Atropo
我能否像在VirtualBox中那样轻松地拍摄和恢复快照? - Necktwi
1
@neckTwi 请看这里的文档 ZFS快照 - Atropo
虽然我点了赞,但我不能接受,因为我是 Git 的粉丝,它太简单了。你能否给我提供 BTRFS 的教程链接以便开始学习? - Necktwi
关于最初的问题,Git repo 最相关的功能可能是跟踪单个文件和目录的更改(例如 git log /usr/sbin/)。据我所知,ZFS 和 BTRFS 快照无法做到这一点。 - Aleksandr Levchuk

0

在 / 文件夹中的另一种方法是白名单方法:

echo '*' > .gitignore  #ignore everything in root
git add -f .gitignore
git add -f /folders_you_wish_to_include   #using -f to add the folders you want to track

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接