If you want see the differences between local and remote files:
$ git diff master origin/master
If you want to remove the file from the Git repository and the filesystem, use:
$ git rm file1.txt
$ git commit -m "remove file1.txt"
But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:
$ git rm --cached file1.txt
$ git commit -m "remove file1.txt"
And to push changes to remote repo
git push origin branch_name
You need to do two commands, the first will "unstage" the file (removes it from the list of files that are ready to be committed). Then, you undo the delete.
If you read the output of the git status command (after the using git rm), it actually tells you how to undo the changes (do a git status after each step to see this).
Unstage the file:
$ git reset HEAD <filename>
Restore it (undo the delete):
$ git checkout -- <filename>
To undo a git push we need to force an update:
git push -f origin HEAD^:master
Get to previous commit (preserves working tree):
git reset --soft HEAD
Get back to previous commit (you'll lose working tree):
git reset --hard HEAD^
Long-form flags:
git add -A
is equivalent togit add --all
git add -u
is equivalent togit add --update
New Files | Modified Files | Deleted Files | ||
---|---|---|---|---|
git add -A |
✔️ | ✔️ | ✔️ | Stage All (new, modified, deleted) files |
git add . |
✔️ | ✔️ | ✔️ | Stage All (new, modified, deleted) files |
git add --ignore-removal . |
✔️ | ✔️ | ❌ | Stage New and Modified files |
git add -u |
❌ | ✔️ | ✔️ | Stage Modified and Deleted files only |
Here is how I rename a tag old
to new
:
$ git tag <new> <old>
$ git tag -d <old>
$ git push --delete origin <old>
$ git push origin :refs/tags/<old>
$ git push --tags
The colon in the push command removes the tag from the remote repository. If you don't do this, Git will create the old tag on your machine when you pull.
Finally, make sure that the other users remove the deleted tag. Please tell them (co-workers) to run the following command:
$ git pull --prune --tags
- https://stackoverflow.com/questions/46786070/how-do-i-show-differences-between-local-and-remote-files-in-git
- https://stackoverflow.com/questions/2047465/how-can-i-delete-a-file-from-a-git-repository
- https://howtogit.archive.pieterdedecker.be/concepts/types-of-changes.html
- https://stackoverflow.com/questions/11727083/how-to-recover-file-after-git-rm-abc-c
- https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add
- https://stackoverflow.com/questions/1028649/how-do-you-rename-a-git-tag
Tanks