git pullディレクトリを削除せずにローカルファイルの変更を無視して、実行する必要がある方法はありますgit cloneか?
rm -rf local_repo && git clone remote_url。
git pullディレクトリを削除せずにローカルファイルの変更を無視して、実行する必要がある方法はありますgit cloneか?
rm -rf local_repo && git clone remote_url。
回答:
ローカルの変更をプルで上書きしたい場合は、作業ツリーがクリーンであるかのようにマージを実行して、作業ツリーをクリーンにします。
git reset --hard
git pull
追跡されていないローカルファイルがある場合git cleanは、それらを削除するために使用できます。使用しgit clean -f、人跡未踏のファイルを削除するために-df追跡されていないファイルやディレクトリを削除すると、-xdf人跡未踏または無視されたファイルやディレクトリを削除します。
一方、ローカルの変更をなんとかして保持したい場合は、プルする前にstashを使用してそれらを非表示にし、後で再適用します。
git stash
git pull
git stash pop
文字通り変更を無視しても意味がないと思いますが、プルの半分はマージであり、コミットされたコンテンツのバージョンとフェッチしたバージョンをマージする必要があります。
git reset、あなたのファイルがまだリモート、読み取りと異なる stackoverflow.com/questions/1257592/...
git reset --hard後者ではなく前者に影響します。リモートの状態に完全にリセットしたい場合git reset --hard origin/<branch>-しかし、多くの場合、この場合、発生する前の2つのコミットは、実行した作業であり、破棄したいものではありません。
私にとっては、以下がうまくいきました:
(1)最初にすべての変更をフェッチします。
$ git fetch --all
(2)次に、マスターをリセットします。
$ git reset --hard origin/master
(3)プル/更新:
$ git pull
あなたはちょうどと同じ結果を与えるコマンドが欲しいだけですrm -rf local_repo && git clone remote_urlよね?この機能も欲しい。私はgitのは、このようなコマンドを提供していない理由(のような不思議ではないgit recloneかgit sync)、どちらのsvn(のようなそのようなコマンドを提供しませんsvn recheckoutかsvn sync)。
次のコマンドを試してください。
git reset --hard origin/master
git clean -fxd
git pull
git clean -fxdから.gitignoreもファイルを削除します。
以下のコマンドは常に機能しません。あなただけの場合:
$ git checkout thebranch
Already on 'thebranch'
Your branch and 'origin/thebranch' have diverged,
and have 23 and 7 different commits each, respectively.
$ git reset --hard
HEAD is now at b05f611 Here the commit message bla, bla
$ git pull
Auto-merging thefile1.c
CONFLICT (content): Merge conflict in thefile1.c
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
等々...
本当にただやる、thebranchをダウンロードし、すべてのローカルの変更を上書きし、やり直します:
$ git checkout thebranch
$ git reset --hard origin/thebranch
これは問題なく動作します。
$ git checkout thebranch
Already on 'thebranch'
Your branch and 'origin/thebranch' have diverged,
and have 23 and 7 different commits each, respectively.
$ git reset --hard origin/thebranch
HEAD is now at 7639058 Here commit message again...
$ git status
# On branch thebranch
nothing to commit (working directory clean)
$ git checkout thebranch
Already on 'thebranch'
Linuxを使用している場合:
git fetch
for file in `git diff origin/master..HEAD --name-only`; do rm -f "$file"; done
git pull
forループは、ローカルリポジトリで変更されたすべての追跡ファイルを削除するためgit pull、問題なく動作します。
これの最も良い点は、追跡されたファイルのみがリポジトリ内のファイルによって上書きされ、他のすべてのファイルは変更されないままになることです。
これは私のために働いた
git fetch --all
git reset --hard origin/master
git pull origin master
受け入れられた回答では、競合エラーが発生します
私は通常:
git checkout .
git pull
プロジェクトのルートフォルダ。
.gitignore
「不要なファイルを.gitignoreに追加することは、最初にそれらをブランチにコミットしていない限り機能します。」
また、実行できます:
git update-index --assume-unchanged filename
https://chamindac.blogspot.com/2017/07/ignoring-visual-studio-2017-created.html