我在 git 中有一些暂存和一些未暂存的更改,以及一些未跟踪的文件。我想保留未提交的更改和未跟踪的文件,并丢弃已提交的更改。
正如您在评论中澄清的那样,您的意思是“......并丢弃分阶段的更改”(而不是已提交的更改)。通常,您会使用git reset撤消git add. 但是在您的情况下,您希望保留未分阶段的更改,因此:
git commit # move staged to a commit, does not touch unstaged changes/unadded files
git checkout HEAD^ # checkout the previously committed version while keeping unstaged changes/unadded files
git branch yourbranchname --force # to grab the branch and move it back as well
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1697 次 |
| 最近记录: |