2015-07-28 19 views
8

Muszę umieścić wszystkie moje zatwierdzenia w jednym zwanym początkowym migawką, aby zwolnić go w Replo github, wiem, że za to podążam thisZgrupuj wszystkie zatwierdzenia w jednym, przed żądaniem pobrania w github

Moje pierwsze pytanie jest, że chcę podzielić się z zewnętrznego repozytorium, a to znaczy:

Jedna uwaga: Tylko nie rób tego na zatwierdzeń, które nie zostały zepchnięte się zewnętrznego repozytorium. Jeśli inni oprą się pracy nad zatwierdzeniami, które usuniesz, możesz napotkać wiele konfliktów. Po prostu nie zmieniaj historii, jeśli została udostępniona innym.

i co się dzieje, chcę umieścić wszystkie moje zobowiązuje się w jedną, jak to zrobić:

znalazłem też to:

# Switch to the master branch and make sure you are up to date. 
git checkout master 
git fetch # this may be necessary (depending on your git config) to receive updates on origin/master 
git pull 

# Merge the feature branch into the master branch. 
git merge feature_branch 

# Reset the master branch to origin's state. 
git reset origin/master 

# Git now considers all changes as unstaged changes. 
# We can add these changes as one commit. 
# Adding . will also add untracked files. 
git add --all 
git commit 

ale nic się nie dzieje:

$ git reset origin/master 
$ git add --all 
$ git commit -m "initial snapshot" 
On branch master 
Your branch is up-to-date with 'origin/master'. 
nothing to commit, working directory clean 
+0

Co otrzymasz od 'git rev-parse głównego pochodzenia/master'?Wygląda na to, że przed uruchomieniem 'git reset' możesz odrzucić swoją pracę. Bez obaw, jeśli znajdziesz go w reflogie ('git log -g'). – user3188445

+0

To co mam: master pochodzenia $ git rev-parse/master 78c4e31d7f813a127603aa93d63eb2c9db8d7c47 78c4e31d7f813a127603aa93d63eb2c9db8d7c47 – anquegi

+0

Ok, więc mistrz powraca na pochodzenia/master. I czy 'git diff' lub' git diff --cached HEAD' pokazuje jakiekolwiek zmiany w twoim drzewie lub indeksie? Jeśli nie, być może będziesz musiał znaleźć zawartość swojego utraconego mistrza za pomocą 'git log -g'. – user3188445

Odpowiedz

18

Najprostszym sposobem na to jest użycie polecenia rebase.

Wyobraź sobie, że to repozytorium

$> git log --oneline 
af28aeb Another test 
a680317 Try something 
d93792b Edit both files 
f23cdbd Second commit add b 
6f456bc First commit add a 

więc trzeba zrobić kilka testów z zobowiązuje af28aeb Another test i a680317 Try something. Chcemy je zgnieść po d93792b Edit both files, aby wyczyścić repozytorium.

Aby to zrobić, że polecenie będzie git rebase -i d93792b

Gdzie -i jest wskazanie, aby wejść w tryb interaktywny i d93792b jest hash popełnić gdzie chcemy absorbe poprzednie.

Uwaga: w przypadku, gdy chcesz zgnieść wszystkie rewizje jak pierwszy, trzeba użyć git rebase --root -i

polecenie to pokaże, że:

pick a680317 Try something 
pick af28aeb Another test 

# Rebase d93792b..af28aeb onto d93792b (  2 TODO item(s)) 
# 
# Commands: 
# p, pick = use commit 
# r, reword = use commit, but edit the commit message 
# e, edit = use commit, but stop for amending 
# s, squash = use commit, but meld into previous commit 
# f, fixup = like "squash", but discard this commit's log message 
# x, exec = run command (the rest of the line) using shell 
# 
# These lines can be re-ordered; they are executed from top to bottom. 
# 
# If you remove a line here THAT COMMIT WILL BE LOST. 
# 
# However, if you remove everything, the rebase will be aborted. 
# 
# Note that empty commits are commented out 

Musisz powiedz komendę rebase, co chcesz zrobić. W takim przypadku proponujemy, aby przeredagować pierwsze popełnić i zgnieść drugi następująco:

reword a680317 Try something 
squash af28aeb Another test 

# Rebase d93792b..af28aeb onto d93792b (  2 TODO item(s)) 
# 
# Commands: 
# p, pick = use commit 
# r, reword = use commit, but edit the commit message 
# e, edit = use commit, but stop for amending 
# s, squash = use commit, but meld into previous commit 
# f, fixup = like "squash", but discard this commit's log message 
# x, exec = run command (the rest of the line) using shell 
# 
# These lines can be re-ordered; they are executed from top to bottom. 
# 
# If you remove a line here THAT COMMIT WILL BE LOST. 
# 
# However, if you remove everything, the rebase will be aborted. 
# 
# Note that empty commits are commented out 

Wtedy twój edytować tekst zostanie otwarty, aby ustawić nowy popełnienia wiadomość.

Fix bug 

# Please enter the commit message for your changes. Lines starting 
# with '#' will be ignored, and an empty message aborts the commit. 
# 
# Date:  Tue Jul 28 08:40:04 2015 +0200 
# 
# rebase in progress; onto d93792b 
# You are currently editing a commit while rebasing branch 'master' on 'd93792b'. 
# 
# Changes to be committed: 
#  new file: c 
# 

Teraz trzeba git commit --amend i git rebase --continue, aby zakończyć proces.

I repozytorium pokaże tak:

$> git log --oneline 
5f98806 Fix bug 
d93792b Edit both files 
f23cdbd Second commit add b 
6f456bc First commit add a 
Powiązane problemy