Git:撤消本地更改; git add。 + git rm? [英] Git: Undo local changes; git add . + git rm?

查看:221
本文介绍了Git:撤消本地更改; git add。 + git rm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助找出一些与Github常见的工作流程。我来自VS TFS背景,所以请原谅我。



撤销待定更改



<让我们说我已经克隆了一个git仓库到我的本地文件系统。此时,项目的本地文件与远程repoistory中的内容完全匹配。

然后我决定对代码进行一些更改,并更改一对夫妇的本地版本文件。在做了一些测试之后,我发现我想放弃我的本地更改并将本地文件恢复到它们在远程repoistory中的内容。



如何撤消这些本地更改,将它们恢复到存储库中的当前版本?



提交所有更改



无论何时修改存储库克隆中本地文件的内容或添加新文件并希望推送更改, git add。,git commit与我的评论,然后git push给我的主人。

然而,当我删除本地文件时,存储库,git add。不会捕获rm更改。相反,我必须在git commit更新存储库之前git rm [filename]。我总是忘记这么做。



是否有git命令会git add。和git rm我在本地删除的任何文件,只需一步?修改本地文件并删除一对之后,我想只发出一条命令,在我git commit之前捕获所有更改。 解决方案 div>


如何撤销这些本地修改,将它们恢复到版本库中的当前版本?`



  git reset --hard 

重置您的索引和工作目录到HEAD)


是否有git命令会git add。和git rm我已经在本地删除了任何文件,只需一步?`



  git add -u 

(它不会添加新文件)

如果您还想添加新文件,请删除rm'ed文件并对文件进行修改:

  git添加-A 


Need help figuring out a couple common workflows with Github. I come from a VS TFS background, so forgive me.

Undoing Pending Changes

Let's say I have cloned of a git repository to my local file system. At this point, the project's local files match exactly what's in the remote repoistory.

Then I decided to make some changes to the code, and change the local versions of a couple files. After doing some testing, I figure out that I want to discard my local changes and revert the local files back to what they are in the remote repoistory.

How do I undo these local changes, restoring them to the current versions in the repository?

Committing all Changes

Whenever I modify the contents of local files in my repository clone, or add new files, and want to push the changes, I issue "git add .", "git commit" with my comments, then "git push" to my master.

However, when I delete a file locally that's tracked in the repository, "git add ." doesn't capture the rm changes. Instead, I have to "git rm [filename]" before I "git commit" to update the repository. I always forget to do this though.

Is there a git command that will "git add ." and "git rm" any files I've deleted locally, in one step? After modifying local files and deleting a couple, I'd like to issue just one command that captures all my changes before I "git commit".

解决方案

How do I undo these local changes, restoring them to the current versions in the repository?`

git reset --hard

(this will reset your index and working directory to HEAD)

Is there a git command that will "git add ." and "git rm" any files I've deleted locally, in one step?`

git add -u

(it wont add new files)

If you also want to add new files, remove rm'ed files and stage modifications to files:

git add -A

这篇关于Git:撤消本地更改; git add。 + git rm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆