我確實在尋找解決方案,但我相信我的情況與我閱讀的有所不同。git:如何在提交時忽略對文件的更改?
我在一個特定的分支上工作,並犯了一個錯誤,編輯文件的方式與分支主題無關,現在希望這些更改不會進入提交。我不想失去這些改變,因爲我會盡量在以後的其他分支上以這種或那種方式提交它們。
我試圖git rm --cached
但後來我看到狀態deleted
我git status
- 將文件被刪除從倉庫中?我不希望這樣 - 我希望它保持不變,不管它是否在我的工作分支上的前一個提交中。
我確實在尋找解決方案,但我相信我的情況與我閱讀的有所不同。git:如何在提交時忽略對文件的更改?
我在一個特定的分支上工作,並犯了一個錯誤,編輯文件的方式與分支主題無關,現在希望這些更改不會進入提交。我不想失去這些改變,因爲我會盡量在以後的其他分支上以這種或那種方式提交它們。
我試圖git rm --cached
但後來我看到狀態deleted
我git status
- 將文件被刪除從倉庫中?我不希望這樣 - 我希望它保持不變,不管它是否在我的工作分支上的前一個提交中。
如果沒有舞臺的變化,他們不會的承諾的一部分,這樣的事情:
git status
# On branch development
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: ResearchProposal.tex
這裏,ResearchProposal.tex
有變化,但他們不會被git commit
承諾。
如果您在單個文件中有兩組更改,您要提交的一些文件和您不需要的文件的一部分文件的內容爲this。
如果你已經在你不希望提交一個文件運行git add
,則需要unstage
它:
git reset HEAD <file>
這樣的:
$ git add ResearchProposal.tex
$ git status
# On branch development
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: ResearchProposal.tex
$ git reset HEAD ResearchProposal.tex
Unstaged changes after reset:
M ResearchProposal.tex
$ git status
# On branch development
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: ResearchProposal.tex
一個可能的解決方案:
git stash
git checkout <another-branch>
git stash apply
git add <one-file>
git commit
git stash
git checkout <original-branch>
git stash apply
運行以下命令您的終端:
git update-index --assume-unchanged
要讓Git重新跟蹤文件,只需運行:
git update-index --no-assume-unchanged path/to/file.txt
只是不要階段的一些文件。這是一個完全正常和平凡的使用Git。對於每一次提交,你都會這樣做。你在使用'git add .'還是'git commit -a'?停止使用它,並開始每一次使用'git add -p' * *。 – meagar