Git Pull Ignorując Lokalne Zmiany?

Czy istnieje sposób, aby zrobić git pull, który ignoruje wszelkie lokalne zmiany plików bez wysadzania katalogu i konieczności wykonywania git clone?

 335
Author: 7ochem, 2010-11-11

8 answers

Jeśli chcesz, aby pull nadpisał lokalne zmiany, wykonując scalanie tak, jakby drzewo robocze było czyste, dobrze, Wyczyść drzewo robocze:

git reset --hard
git pull

Jeśli istnieją nie śledzone pliki lokalne, możesz użyć git clean, aby je usunąć. Użyj git clean -f, aby usunąć nie śledzone pliki, -df, Aby usunąć nie śledzone pliki i katalogi oraz -xdf, aby usunąć nie śledzone lub ignorowane pliki lub katalogi.

Jeśli z drugiej strony chcesz zachować lokalne modyfikacje, użyj stash, aby je ukryć wyjąć przed pociągnięciem, a następnie ponownie je zastosować:

git stash
git pull
git stash pop

Myślę, że nie ma sensu dosłownie ignorować zmiany, chociaż - połowa pull to merge, i musi połączyć zatwierdzone wersje treści z wersjami pobranymi.

 588
Author: Cascabel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-11 17:25:24

Dla mnie zadziałało:

(1) Najpierw pobranie wszystkich zmian:

$ git fetch --all

(2) następnie zresetuj master:

$ git reset --hard origin/master

(3) Pull / update:

$ git pull
 166
Author: Artur Barseghyan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-23 08:42:37

Komenda bellow nie będzie działać zawsze . Jeśli tylko:

$ 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.

I tak dalej...

To naprawdę zacznij od nowa, ściągając gałąź i nadpisując wszystkie lokalne zmiany, po prostu zrób:


$ git checkout thebranch
$ git reset --hard origin/thebranch

To zadziała.
$ 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'
 16
Author: Dr Beco,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-24 00:10:45

Spójrz na git stash aby umieścić wszystkie lokalne zmiany w "pliku stash" i powrócić do ostatniego commita. W tym momencie możesz zastosować Ukryte zmiany lub je odrzucić.

 7
Author: Seth Johnson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-11 17:23:58

Jeśli jesteś na Linuksie:

git fetch
for file in `git diff origin/master..HEAD --name-only`; do rm -f "$file"; done
git pull

Pętla for usunie wszystkie śledzone pliki, które zostały zmienione w lokalnym repo, więc git pull będzie działać bez żadnych problemów.
Najładniejszą rzeczą jest to, że tylko śledzone pliki zostaną nadpisane przez pliki w repo, wszystkie inne pliki pozostaną nietknięte.

 7
Author: Strahinja Kustudic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-24 16:19:31

Po prostu chcesz polecenia, które daje dokładnie taki sam wynik jak rm -rf local_repo && git clone remote_url, prawda? Chcę też tę funkcję. Zastanawiam się, dlaczego git nie dostarcza takiego polecenia (np. git reclone Czy git sync), ani svn nie dostarcza takiego polecenia(np. svn recheckout Czy svn sync).

Spróbuj wykonać następujące polecenie:

git reset --hard origin/master
git clean -fxd
git pull
 7
Author: Victor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-03-12 08:26:19
git fetch --all && git reset --hard origin/master
 6
Author: Luca C.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-12 15:26:54

Pobierze bieżącą gałąź i spróbuje zrobić szybki postęp do master:

git fetch && git merge --ff-only origin/master
 0
Author: Petah,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-05 21:04:33