An Interest In:
Web News this Week
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
- March 14, 2024
GIT - Unorthodox commands I use from time to time
Hello Coders,
This article presents a few commands that I use from time to time to cover my programming mistakes or just shortcut things in my GIT repositories.
I must warn beginners (and not only) to double-check the effects using test repositories before applying the mentioned commands on production repositories.
Thanks for reading! Content provided by AppSeed - a platform used by 2k+ developers across the globe.
GIT - Drop local changes
Warn: you might lose valuable work
$ git reset --hard origin/master
GIT - Reset to Commit
Warn: All commits above the used one are lost
$ # We assume the Commit hash is '288c168'$ git reset --hard 288c168$ git push --force origin master
GIT - Print modified files
This command is the safest one and I'm using it a lot to scan for changes.
$ # List all changes$ git add -A -n$ $ # Filter the output using grep$ git add -A -n | grep 'something'
GIT - Ignore files permissions on DIFF
This case might occur if the development PC uses Windows and production is on Linux. To extract the relevant changes and ignore the permissions of the files, the below command can be used:
$ # Configure GIT to ignore changes on files perms$ git config core.filemode false
GIT - Update single (LOCAL) file
Useful when we need to update a single local file with the remote version. The update can be done from any branch - our sample command uses the project master branch.
git checkout origin/master -- app/some-file.html
GIT - Update forked project
This is useful when we want to update a forked project with the latest changes from the parent project.
$ # CD inside the forked project$ cd forked-project$$ # Fetch all branches of remote upstream$ git fetch upstream$$ # Rewrite your master with upstreams master using git rebase.$ git rebase upstream/master$$ # Save changes to our forked project$ git push origin master --force
Git resources
- GIT - official website
- Top 20 Git Commands - with Examples
Thank you! Btw, my (nick)name is Sm0ke and I'm pretty active also on Twitter.
Original Link: https://dev.to/sm0ke/git-unorthodox-commands-i-use-from-time-to-time-10fj
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To