GitHub如何在保留当前未提交代码的同时检查上一次提交的文件?
我知道这是一个简单的问题,但我不知道如何在git中实现它 例如,与上次提交相比,我更改了第10~15行。但是现在我想看看原始的第10~15行是什么样子的。因此,我需要返回到上次提交,并能够返回到当前代码而不提交它们。使用命令保存当前更改而不提交它们,稍后再返回 从文件中: 隐藏将获取工作目录的脏状态 — 就是, 您修改的跟踪文件和阶段性更改 — 并将其保存在 可以随时重新应用的未完成更改的堆栈(即使在 (另一个分支) 下面是在GitHub如何在保留当前未提交代码的同时检查上一次提交的文件?,git,Git,我知道这是一个简单的问题,但我不知道如何在git中实现它 例如,与上次提交相比,我更改了第10~15行。但是现在我想看看原始的第10~15行是什么样子的。因此,我需要返回到上次提交,并能够返回到当前代码而不提交它们。使用命令保存当前更改而不提交它们,稍后再返回 从文件中: 隐藏将获取工作目录的脏状态 — 就是, 您修改的跟踪文件和阶段性更改 — 并将其保存在 可以随时重新应用的未完成更改的堆栈(即使在 (另一个分支) 下面是在master分支上使用隐藏功能的示例用法: 1) 比如说,上次提交时提
master
分支上使用隐藏功能的示例用法:
1) 比如说,上次提交时提交了2个文件
# Commit message: Adding file1.txt and file2.txt
file1.txt
file2.txt
2) 检查是否没有要提交的内容
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
3) 编辑file1.txt
$ vim file1.txt
4) 现在,工作目录处于脏状态
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
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: file1.txt
6) 查看提交时的file1.txt
(即在本地修改之前)
7) 看看藏品清单
$ git stash list
stash@{0}: WIP on master: e1b8933 Adding file1.txt and file2.txt
8) 从存储中恢复更改
$ git stash apply
On branch master
Your branch is up-to-date with 'origin/master'.
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: file1.txt
no changes added to commit (use "git add" and/or "git commit -a")
$git隐藏应用
论分行行长
您的分支机构是最新的“原始/主”分支机构。
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git签出--…”放弃工作目录中的更改)
修改:file1.txt
未向提交添加任何更改(使用“git add”和/或“git commit-a”)
您可以使用git diff
来显示差异
您可以使用git show HEAD:foo.txt原样显示文件。您可以使用
git隐藏
然后,您可以使用
git签出[修订版]
要恢复,请使用git checkout[分支机构名称]
比如说,你的分支是大师级的,试试这个吧
git签出主机
若要恢复编辑,请使用
git stash pop
1.git stash
#-k to keep the index intact, -u to stash the untracked files
git stash push -k -u
#checkout the previous commit xxx
git checkout xxx
#go back to the original commit ooo
git checkout ooo
#apply the stash to restore the uncommitted changes
git stash apply --index
2.git工作树
#create a worktree and checkout the previous commit xxx's code under /path/foo
git worktree add /path/foo xxx
#the uncommitted changes are still in the current repo
#remove the worktree
git worktree remove /path/foo
3.git秀
#show the content of the previous commit xxx's file bar.txt
git show xxx:bar.txt
#show Lines 10~15
git show xxx:bar.txt | sed -n 10,15p
4.怪罪
#show Line 10-15 of the previous commit xxx's file bar.txt
git blame -s -L 10,15 xxx -- bar.txt
我想您可以将当前更改添加到临时分支,然后将其删除。谢谢您的评论。这很有帮助。我将转到文档以了解有关git隐藏的详细信息。
#show the content of the previous commit xxx's file bar.txt
git show xxx:bar.txt
#show Lines 10~15
git show xxx:bar.txt | sed -n 10,15p
#show Line 10-15 of the previous commit xxx's file bar.txt
git blame -s -L 10,15 xxx -- bar.txt