пʼятниця, 9 серпня 2019 р.

GIT remove commit

Small hints for myself regarding GIT.
Imagine we added 1.txt to some project and committed this file:
git add 1.txt
git commit -m 'test 1'
Then we added another file 2.txt and also committed:
git add 2.txt
git commit -m 'test 2'

After manipulations above we have the following situation:
$ git log --graph
* commit 53ec09a2cee2444877233ceca32c15779bb1d02d (HEAD -> master)
| Author: Yurii Petrovskyi
| Date:   Fri Aug 9 10:35:32 2019 +0300
|
|     test 2
|
* commit afb41e2d1fbab67a8cfaf316d41f81b73138b730
| Author: Yurii Petrovskyi
| Date:   Fri Aug 9 10:35:07 2019 +0300
|
|     test 1
|
* commit 0796e3cd0b010b3e84f565fd777811bfc3b225c4 (origin/master)

Then we need to undo the last commit (where we added 2.txt). In this case, it depends on do we want to save 2.txt file or we want to delete it. If we want to save the file and reset the last commit we need to use the next command:
git reset --soft HEAD~1
if we do not need this file at all:
git reset --hard HEAD~1

There is another scenario. We don`t want to push 1.txt from the first commit, so we should remove the file from repository's history:

git rm --cached 1.txt
git commit --amend -CHEAD

After commands above our "test 2" commit will contain removed 1.txt file and if we push it to the remote only 2.txt will be sent.

Also if we want to revert the whole specific commit we can use:
git revert commit_id

For example, I reverted "test 1" commit and this is a result:
git revert afb41e2d1fbab67a8cfaf316d41f81b73138b730
git log
commit 3ff659b964ca741a8c71dfa9ba45bcc74b66aa90 (HEAD -> master)
Author: Yurii Petrovskyi
Date:   Fri Aug 9 12:45:32 2019 +0300

    Revert "test 1"

    This reverts commit afb41e2d1fbab67a8cfaf316d41f81b73138b730.

commit 2d006836dda2d5558b4e1d2701b291c5187abfd1
Author: Yurii Petrovskyi
Date:   Fri Aug 9 12:43:44 2019 +0300

    test 2

commit afb41e2d1fbab67a8cfaf316d41f81b73138b730
Author: Yurii Petrovskyi
Date:   Fri Aug 9 10:35:07 2019 +0300

    test 1

commit 0796e3cd0b010b3e84f565fd777811bfc3b225c4 (origin/master)

If you pushed some changes and it was a mistake, in that case I used the following commands:
git reset --soft HEAD~1
git push origin -f

вівторок, 6 серпня 2019 р.

j_spring_security_check and Spring Security 4 and 405

Long story short, I migrated from Spring Security 3 to version 4.0.3.RELEASE. When I changed the version in pom file I faced with 405 error. In my login.jsp I had something like that:
*(I changed the character "<" to "!" to display the code)

!form style="margin-bottom: 0px;" action="../../j_spring_security_check" method="post">
Username:!input type="text" name="j_username" />!br/>
Password:!input type="password" name="j_password" />!br/>

Digging through Stackoverflow and other articles I found this useful link (note for the future: try to search in official documentation first :-) ):
https://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-xml.html#m3to4-xmlnamespace-form-login

So now I have login.jsp with the following text:

!form style="margin-bottom: 0px;" action="!c:url value='/login' />" method="POST">
Username:!input type="text" name="username" />!br/>
Password:!input type="password" name="password" />!br/>
!input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> !br/>
!input type="submit" value="Login" />

Update: For now I do not need CSRF filter in my project, so I removed one line from the code above (crossed out text) and added the following string in my spring-security.xml:
<security:csrf disabled="true" />