Gitでは、私のライセンスとReadmeファイルは削除されたとマークされていますが、まだ残っていますか?

Gitでは、私のライセンスとReadmeファイルは削除されたとマークされていますが、まだ残っていますか?

読んでくれてありがとう!

私は私の設定を始めたGitとGitHubを使用したポイントファイルの設定問題が発生しました。 myを$HOMEgitワークツリーとして使用し、.gitエイリアスを使用して-directoryをmy -directoryに入れました。$HOME/.dotfiles

alias dotfiles="git --git --git-dir=$HOME/.dotfiles/.git/ --work-tree=$HOME"

GitHubの新しいリポジトリそして追加されました特許そして閲覧ファイルそこに。次のようにリポジトリを複製すると:

git clone \<url to the repository\> $HOME/.dotfiles

これ特許そして閲覧ファイル.dotfiles- ディレクトリにありますが、コマンドは次のようになります。

dotfiles status

次のようにリストします。削除済み

欲しくない〜したい特許そして閲覧ファイル$HOMEは - ディレクトリにあります。これは-ディレクトリに残る必要があります$HOME/.dotfiles

この問題についてどうすればよいですか?

ベストアンサー1

実際には、githubとgitlabが尊重するマスターブランチにLICENSEファイルとREADMEファイル(githubまたはgitlabのプロジェクトのホームディレクトリに表示されます)があるかもしれませんが、ホームディレクトリにはないかもしれません。最も簡単なソリューションREADMEを.githubプロジェクトのメインフォルダに入れるのですが、フラッグハブ

しかし、実際にはgitlabとgithubのプロジェクトホームページにはLICENSEとREADMEが表示されます。

1.ベアGitリポジトリを起動するか、既存のリポジトリをコピーします。

xadf用のベアgitリポジトリを起動し、追加情報やライセンスなしで初期コミットを実行し、エイリアスを作成します。エイリアスは必要に応じて指定できますが(たとえばdotfiles)、入力しやすくするために使用しましたgitdf

# Initialize a bare git directory
git init --bare $HOME/.dotfiles

# Sets up an alias so you don't have to type long commands
alias gitdf='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'

# Adds a remote where you'd push your changes
gitdf remote add origin [email protected]:yourusername/dotfiles.git

# Do not display untracked files (it would be a ton of untracked files in an actual home tree
gitdf config status.showUntrackedFiles no

または、すでにdotfilesリポジトリがある場合は、それを自宅にコピーできます。

# Clone existing repo with separate git directory (here it is ~/.dotfiles), and the work tree in a separate, temporary directory .dotfiles-temp
git clone --separate-git-dir=$HOME/.dotfiles https://github.com/yourusername/dotfiles.git .dotfiles-temp

# Copy the content of the temporary work tree to ~/
rsync --recursive --verbose --exclude '.git' .dotfiles-temp/ $HOME/

# Remove the temporary work tree
rm --recursive .dotfiles-temp

# Sets up an alias so you don't have to type long commands
alias gitdf='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'

# Sets remote directory
gitdf remote set-url origin [email protected]:yourusername/dotfiles.git

.bashrcログインするたびにエイリアスが維持されるように、エイリアスにエイリアスを追加する必要があります。

2. 次にポイントを作成します。

これは、実際のマスターツリーで見ている実際の分岐です。たとえば、home支店。

# Make branch 'home'
gitdf checkout -b home

# You may need to also add the branch to gitlab or github
gitdf push --set-upstream origin home

3. ブランチマスターで README と LICENSE を追加します。

その後、必要に応じてブランチマスターから追加情報とライセンスを安全に追加できます。これはgitlabまたはgithubのプロジェクトのホームページから情報を提供するためにのみ使用されます。そのファイルは、ブランチホームディレクトリのコミット履歴には表示されません。お住まいの地域の支店に導入してはいけません。

# Switch back to branch 'master'
gitdf checkout master

# Make readme and license
touch ~/LICENSE ~/README.md

# Add them to your bare git repo
gitdf add LICENSE README.md

# Commit
gitdf commit

# Push
gitdf push

4. 実際の作業点のみを変更します。

homeその後、ドットファイルの実際のチェックアウト分岐である分岐に戻ります。ここで、readme またはライセンスファイルはコミット履歴には表示されません。

gitdf checkout home

投稿設定

homeその後、構成ファイルへの変更は、そのブランチまたはそのブランチから派生したブランチでのみ行われますhome。時々(または定期的に)マスターにマージする必要があるかもしれません。

# Go to branch master
gitdf checkout master

# merge branch home to branch master
gitdf merge home

# push to remote
gitdf push

LICENSEホームブランチには合計がないため、README.mdマージによって競合は発生しません。

ただし、別の方法で(たとえば、ブランチで)実行しないでください。homeこれは、ホームディレクトリに、およびが追加されるgitdf merge masterためです。LICENSEREADME.md

各特定ポイントの複数のマシン固有の構成

追加のボーナスを使用して他の特定の目的に分岐することもできますhome(たとえば、タスク固有の構成にwork基づいている必要がありますが、その分岐がある分岐)。home

# Check if we're in branch home
gitdf status -sb

# Checkout to branch home if we are not
gitdf checkout home

# Note that the -b flag means make branch if it does not exist
gitdf checkout -b work

# Add new branch to remote
gitdf push --set-upstream origin work

# Configure or add work-specific changes then commit
gitdf add .config/work/related/configfile
gitdf commit

# Push to remote
gitdf push

後でブランチに変更を適用するときにhomeすべきことは、workその内容をブランチに含めることだけです。

# move to branch work
gitdf checkout work

# merge branch home to branch home
gitdf merge home

# Push to remote
gitdf push

たとえば、別のブランチがある場合(すべてhomeブランチから開始して新しいブランチを作成する必要があることを意味します)、必要に応じてホームをそのブランチにマージすることもできます。必要に応じて変更をマージすることもできます。homelaptophome

しかし、実際には、まず共有構成を作成し、必要なhomeブランチとmaster

したがって、次のようにマージ方向を視覚化できます。

master < home <> work
              <> laptop

自宅でコンソール、職場、ノートブックにマージしたり、職場、ノートブックから自宅にマージしたり、コンソールから自宅にマージしたりしないでください。

実際のアプリケーション

恥ずかしいプラグとして、内でこのgitエイリアスメソッドを設定する方法を見ることができます。ドットファイルストア。上記の手順をより完全かつ適度に複雑に実装したものです。これをインストールするには、インストーラとコントローラスクリプト(xdf)、実行可能にし、私のパスのどこかに配置します。

# Make directory, if it isn't present already
mkdir -p ~/.local/bin

# Download the executable into your local bin directory
wget -O ~/.local/bin/xadf https://gitlab.com/heno72/xadf/-/raw/master/.local/bin/xadf

# Make it executable
chmod +x ~/.local/bin/xadf

# Export path to local bin if it isn't set up already
PATH=~/.local/bin:$PATH

# Install xadf minimally
xadf --minimal-install

このスクリプトは、後で使用する構成ファイルの作成(エイリアスと一部の機能)を含む、ステップ1(コピー)、ジョブブランチへのチェックアウト(デフォルトは上記のブランチtrunkと同じ)を処理できます。home~/.config/xadf

# initialize, configure, load, and manage
xadf --init-bare --seat ~/.dotfiles
xadf --custom-install --seat ~/.dotfiles
. ~/.bashrc
xadf config status.showUntrackedFiles no

または、リモートで独自のGitリポジトリがすでに存在する場合:

# Clone and configure from a custom url, load, and manage
xadf -i -s [email protected]:heno72/xadf-gb.git --seat ~/.dotfiles
. ~/.bashrc
xadf status -sb

ホームフォルダにすでにgitディレクトリがある場合は、xadfを使用して管理できます。

xadf --custom-install --seat ~/.dotfiles
. ~/.bashrc

インストールして.bashrcを取得したら、他のgitコマンドと同じようにスクリプトを使用できます。

# Adds a new config file to tracked file
xadf add .config/new/config/file

# Commit changes
xadf commit

# Push changes to remote
xadf push

# Change working branch
xadf checkout newbranch

または所定のアクション:

xadf -l         # list all tracked files
xadf -l .config # list all tracked files in ~/.config

おすすめ記事