美文网首页
Git的使用场景

Git的使用场景

作者: 默念2009 | 来源:发表于2016-10-27 19:40 被阅读0次

以此文记述工作中遇到的Git问题,及其解决方法。

恢复被同事误删的文件

场景:同事认为文件 useful.js 在当前项目中没有用,把它删了,提交代码之后,其他同事又提交了好几次代码。
解决方法

S1 查看哪个 commit 删除了该文件
// git log [--] <path>
// Show only commits that are enough to explain how the files
// that match the specified paths came to be.
// To prevent confusion with options and branch names, paths may
// need to be prefixed with "--" to separate them from options 
// or refnames.
git log -- path_to/useful.js

S2 找到 useful.js 被删除提交之前的 [commit]

S3 执行git命令恢复文件
// After running git reset <paths> to update the index entry, you can
// use git-checkout to check the contents out of the index to the
// working tree. Alternatively, using git-checkout and specifying a
// commit, you can copy the contents of a path out of a commit to the
// index and to the working tree in one go.
git reset [commit] path_to/useful.js
git checkout -- path_to/useful.js

// display the deleted file
git ls-files --deleted

相关文章

  • git使用

    本文通过以下四个部分讲解git的使用 Git配置 Git使用场景 Git分支管理方法 常用git命令 在讲解...

  • 6.Git 实战系列:场景:丢弃当前修改,重新检出

    场景:git checkout -f的使用场景 wangxiaodeMacBook-Pro:playgit wan...

  • IDEA使用Git协同开发

    使用场景 场景一:组长创建项目并提交到远程Git仓库 场景二:组员从远程Git仓库上获取项目源码 场景三:组长修改...

  • Git自学成才——git merge

    概念 git merge 和 git rebase 是使用率非常高的两条指令本文对git merge的日常使用场景...

  • git常见使用 场景

    给分支 标记tag git checkout branchName切换到 分支 git log查看分支 提交记录i...

  • git使用场景

    1、git 只提交部分文件 有时,在git push之后,才发现还有一些代码需要进行很小的改动,这些改动在原则上不...

  • Git的使用场景

    以此文记述工作中遇到的Git问题,及其解决方法。 恢复被同事误删的文件 场景:同事认为文件 useful.js 在...

  • git密码重置

    场景:使用git + 码云,码云登录密码修改后,git 也需要重新设置密码 使用管理员权限打开 git bush ...

  • git log --grep 用法

    使用方法:git log 支持正则表达式搜索提交消息 git log --grep 使用场景:比...

  • Git 撤销 git add,git commit 添加错的文件

    场景一、 使用 git add . 添加了当前目录所有文件,导致提交了不应该的文件 首先使用 git status...

网友评论

      本文标题:Git的使用场景

      本文链接:https://www.haomeiwen.com/subject/qlimyttx.html