# one commit(my-branch)$ git reset--hardHEAD^# two commits(my-branch)$ git reset--hardHEAD^^# four commits(my-branch)$ git reset--hardHEAD~4# or(main)$ git checkout-f 1. 2. 3. 4. 5. 6. 7. 8. 重置某个特殊的文件, 你可以用文件名做为参数: $ git reset filename 1. 我想...
$ git status # On branch 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: files/Hulk.png # modified: files/Hulk_2.png # no changes...
When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context. However, with this option, a three-w...
# 将暂存区的指定文件内容覆盖到工作区 $ git checkout -- <pathspec> # 以补丁的方式将暂存区的指定文件内容覆盖到工作区(-p全称--patch) $ git checkout -p -- <pathspec> # 将指定提交的内容覆盖到暂存区和工作区 $ git checkout <commit> # 将指定提交的指定文件内容覆盖到暂存区和工作区 $ git ...
Run the command multiple times git checkout -- path/to/file/one git checkout -- path/to/file/two Or specify the multiple files in the same line: git checkout -- path/to/file/one path/to/file/two You can also specify entire folders which will recurse to all files below them. gi...
git checkout -b (create and switch branch in one command) git branch -d git log --oneline --decorate --graph --all (see all branches at once) git merge (combines changes on different branches) Handle Merge Conflicting Git命令是每一位程序猿几乎天天会用到的命令。尤其是在遇到棘手的问题和复...
# Make some changes to the file echo "This is a change" > test01 echo "and this is another change" > test02 # Check the changes via the diff command git diff # Commit the changes, -a will commit changes for modified files
$ git checkout HEAD^ myfile $ git add -A $ git commit --amend 1. 2. 3. 这将非常有用,当你有一个开放的补丁(open patch),你往上面提交了一个不必要的文件,你需要强推(force push)去更新这个远程补丁。 我想删除我的的最后一次提交(commit) ...
$ git checkoutHEAD^myfile $ git add-A$ git commit--amend 这将非常有用,当你有一个开放的补丁(open patch),你往上面提交了一个不必要的文件,你需要强推(force push)去更新这个远程补丁。 我想删除我的的最后一次提交(commit) 如果你需要删除推了的提交(pushed commits),你可以使用下面的方法。可是,这会...
场景一:当你改乱了工作区域某个文件的内容,想直接丢弃工作区的修改时,直接用命令:git checkout -- 文件名。(注:git checkout -- file命令中的--很重要,没有--,就变成了“切换到另一个分支”的命令) 场景二:当你不但改乱了工作区某个文件的内容,还添加到了暂存区,想丢弃修改需要分两步走。